-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
71 lines (60 loc) · 2.03 KB
/
Main.java
File metadata and controls
71 lines (60 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package Browsie;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
// the main class
public class Main extends JFrame {
private JTextField field = new JTextField();
private JEditorPane display = new JEditorPane();
private JScrollPane scrollPane = new JScrollPane(display);
//the main function
public static void main(String[] args) {
Main browser = new Main();
browser.frameHandler();
}
public void frameHandler() {
setTitle("Browser");
setSize(1280, 800);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
setLayout(null);
setLocationRelativeTo(null);
addComponentsToFrame(getContentPane());
}
public void addComponentsToFrame(Container pane) {
Insets insets = getInsets();
pane.add(field);
pane.add(scrollPane);
Font font = new Font("Sans", Font.ITALIC, 12);
field.setFont(font);
field.setBounds(8 - insets.left, 30 - insets.top, 1268, 20);
scrollPane.setBounds(8 - insets.left, 30 - insets.top, 1268, 830);
actionListenerCalls();
}
private void actionListenerCalls() {
field.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
load("http://" + event.getActionCommand());
}
});
display.addHyperlinkListener(
new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
load(event.getURL().toString());
}
}
}
);
}
private void load(String addressText) {
try {
display.setPage(addressText);
field.setText(addressText);
} catch (Exception e) {
System.out.println("Malformed URL!");
}
}
}