Repository navigation
Expand file tree
/
Copy pathReadFile.java
More file actions
88 lines (67 loc) · 1.97 KB
/
Copy pathReadFile.java
File metadata and controls
88 lines (67 loc) · 1.97 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
* This GUI consists of 2 parts
* One address bar that is JTextField
* and the rest of the content loaded in JEditorPane
* @author Hamid(the6ixdev)
*/
public class ReadFile extends JFrame {
private JTextField addressBar;
private JEditorPane display;
private JTextField addressBar2;
//constructor
public ReadFile() {
super("Title for the browser");
addressBar = new JTextField("Enter a URL please!");
addressBar2 = new JTextField();
add(addressBar2,BorderLayout.SOUTH);
/* The way submission is done is through "enter" button
* therefore an action listener for it is created */
// Action Listener command
addressBar.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
/* Go to that URL,Display
* we create a seperate method */
// What it does is that it gets the string of JTextField
loadContent(e.getActionCommand());
}
}
);
add(addressBar,BorderLayout.NORTH);
display = new JEditorPane();
display.setEditable(false);
// Sits on display and watches all links
display.addHyperlinkListener(
new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
/*
* We care only about the click event now
*/
if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
loadContent(e.getURL().toString());
}
}
}
);
add(new JScrollPane(display),BorderLayout.CENTER);
setSize(1080,720);
setVisible(true);
}
// loadContent Method out of constructor
private void loadContent(String userText){
try {
// most important line of code
display.setPage(userText);
addressBar.setText(userText);
}catch(Exception e) {
addressBar2.setText("You didn't enter a proper URL!");
System.out.println("you didn't enter a proper URL-Console");
}
}
}