-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankHelp.java
115 lines (87 loc) · 2.31 KB
/
BankHelp.java
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package bank;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.*;
import javax.swing.text.*;
import javax.swing.event.*;
public class BankHelp extends JInternalFrame {
public BankHelp (String title, String filename) {
// super(Title, Resizable, Closable, Maximizable, Iconifiable)
super (title, false, true, false, true);
setSize (500, 350);
HtmlPane html = new HtmlPane (filename);
setContentPane (html);
setVisible (true);
}
BankHelp() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class HtmlPane extends JScrollPane implements HyperlinkListener {
JEditorPane html;
public HtmlPane(String filename) {
try {
File f = new File (filename);
String s = f.getAbsolutePath();
s = "file:"+s;
URL url = new URL(s);
html = new JEditorPane(s);
html.setEditable(false);
html.addHyperlinkListener(this);
JViewport vp = getViewport();
vp.add(html);
}
catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
}
catch (IOException e) {
System.out.println("IOException: " + e);
}
}
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
linkActivated(e.getURL());
}
}
protected void linkActivated(URL u) {
Cursor c = html.getCursor();
Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
html.setCursor(waitCursor);
SwingUtilities.invokeLater(new PageLoader(u, c));
}
class PageLoader implements Runnable {
PageLoader(URL u, Cursor c) {
url = u;
cursor = c;
}
public void run() {
if (url == null) {
html.setCursor(cursor);
Container parent = html.getParent();
parent.repaint();
}
else {
Document doc = html.getDocument();
try {
html.setPage(url);
}
catch (IOException ioe) {
html.setDocument(doc);
getToolkit().beep();
}
finally {
url = null;
SwingUtilities.invokeLater(this);
}
}
}
URL url;
Cursor cursor;
}
public static void main(String args[])
{
BankHelp bh= new BankHelp();
}
}