forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanisMinor.java
More file actions
70 lines (58 loc) · 1.92 KB
/
Copy pathCanisMinor.java
File metadata and controls
70 lines (58 loc) · 1.92 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
//file: CanisMinor.java
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
public class CanisMinor extends JFrame {
protected JEditorPane mEditorPane;
protected JTextField mURLField;
public CanisMinor(String urlString) {
super("CanisMinor v1.0");
createGUI(urlString);
}
protected void createGUI( String urlString ) {
Container content = getContentPane();
content.setLayout(new BorderLayout());
JToolBar urlToolBar = new JToolBar( );
mURLField = new JTextField(urlString, 40);
urlToolBar.add(new JLabel("Location:"));
urlToolBar.add(mURLField);
content.add(urlToolBar, BorderLayout.NORTH);
mEditorPane = new JEditorPane( );
mEditorPane.setEditable(false);
content.add(new JScrollPane(mEditorPane), BorderLayout.CENTER);
openURL(urlString);
mURLField.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {
openURL(ae.getActionCommand( ));
}
});
mEditorPane.addHyperlinkListener(new LinkActivator( ));
setSize(500, 600);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
protected void openURL(String urlString) {
try {
URL url = new URL(urlString);
mEditorPane.setPage(url);
mURLField.setText(url.toExternalForm( ));
}
catch (Exception e) {
System.out.println("Couldn't open " + urlString + ":" + e);
}
}
class LinkActivator implements HyperlinkListener {
public void hyperlinkUpdate(HyperlinkEvent he) {
HyperlinkEvent.EventType type = he.getEventType( );
if (type == HyperlinkEvent.EventType.ACTIVATED)
openURL(he.getURL().toExternalForm( ));
}
}
public static void main(String[] args) {
String urlString = "http://www.oreilly.com/catalog/java2d/";
if (args.length > 0)
urlString = args[0];
new CanisMinor( urlString ).setVisible( true );
}
}