blob: ca55ceb1065ad61d8f23897f9d8f4841c721331a (
plain)
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
|
/* URLLaden.java */
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
class URLButton
extends Button
{
private URL url;
public URLButton(String label, URL url)
{
super(label);
this.url = url;
}
public URL getURL()
{
return url;
}
}
public class URLLaden
extends Applet
implements ActionListener
{
Vector buttons;
public void init()
{
super.init();
setLayout(new FlowLayout());
addNotify();
buttons = new Vector();
for (int i=1; ; ++i) {
String s = getParameter("button"+i);
if (s == null) {
break;
}
try {
StringTokenizer st = new StringTokenizer(s,",");
String label = st.nextToken();
String urlstring = st.nextToken();
URL url;
if (urlstring.charAt(0) == '=') {
urlstring = urlstring.substring(1);
url = new URL(getDocumentBase(),urlstring);
} else {
url = new URL(urlstring);
}
URLButton button = new URLButton(label,url);
button.addActionListener(this);
add(button);
buttons.addElement(button);
} catch (NoSuchElementException e) {
System.out.println("Button"+i+": "+e.toString());
break;
} catch (MalformedURLException e) {
System.out.println("Button"+i+": "+e.toString());
break;
}
}
}
public void actionPerformed(ActionEvent event)
{
URLButton source = (URLButton)event.getSource();
Enumeration en = buttons.elements();
while (en.hasMoreElements()) {
URLButton button = (URLButton)en.nextElement();
if (button == source) {
System.out.println(
"showDocument("+button.getURL().toString()+")"
);
getAppletContext().showDocument(button.getURL());
}
}
}
}
|