ptg7068951
Displaying Revolving Links 277
9:
10: String[] pageTitle= new String[6];
11: URL[] pageLink= newURL[6];
12: Color butterscotch= new Color(255, 204, 158);
13: int current= 0;
14: Thread runner;
15:
16: public voidinit() {
17: pageTitle = new String[] {
18: “Sun’s Java site”,
19: “Cafe au Lait”,
20: “JavaWorld”,
21: “Java in 24 Hours”,
22: “Sams Publishing”,
23: “Workbench”
24: };
25: pageLink[0] = getURL(“http://java.sun.com”);
26: pageLink[1] = getURL(“http://www.ibiblio.org/javafaq”);
27: pageLink[2] = getURL(“http://www.javaworld.com”);
28: pageLink[3] = getURL(“http://www.java24hours.com”);
29: pageLink[4] = getURL(“http://www.samspublishing.com”);
30: pageLink[5] = getURL(“http:// workbench.cadenhead.org”);
31: Button goButton = new Button(“Go”);
32: goButton.addActionListener(this);
33: FlowLayout flow = new FlowLayout();
34: setLayout(flow);
35: add(goButton);
36: }
37:
38: URL getURL(String urlText) {
39: URL pageURL = null;
40: try {
41: pageURL = new URL(getDocumentBase(), urlText);
42: } catch(MalformedURLException m) { }
43: returnpageURL;
44: }
45:
46: public voidpaint(Graphics screen) {
47: Graphics2D screen2D = (Graphics2D) screen;
48: screen2D.setColor(butterscotch);
49: screen2D.fillRect(0, 0, getSize().width, getSize().height);
50: screen2D.setColor(Color.black);
51: screen2D.drawString(pageTitle[current], 5, 60);
52: screen2D.drawString(“” + pageLink[current], 5, 80);
53: }
54:
55: public voidstart() {
56: if (runner== null) {
57: runner= new Thread(this);
58: runner.start();
59: }
LISTING 19.2 Continued