Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

278 HOUR 19:Creating a Threaded Program


60: }
61:
62: public voidrun() {
63: Thread thisThread = Thread.currentThread();
64: while (runner== thisThread) {
65: current++;
66: if (current> 5) {
67: current= 0;
68: }
69: repaint();
70: try {
71: Thread.sleep(10000);
72: } catch(InterruptedException e) {
73: // do nothing
74: }
75: }
76: }
77:
78: public voidstop() {
79: if (runner!= null) {
80: runner= null;
81: }
82: }
83:
84: public voidactionPerformed(ActionEvent event) {
85: if (runner!= null) {
86: runner= null;
87: }
88: AppletContext browser = getAppletContext();
89: if (pageLink[current] != null) {
90: browser.showDocument(pageLink[current]);
91: }
92: }
93: }

After you save the program, you need to create a web page in which to put
the applet—it won’t work correctly if you use Run, Run File to test it in
NetBeans because links can’t be opened that way. Create a new web
page—choose File, New File, and then click Other to find the HTMLFile
option in the File Types pane of the Choose File Type dialog. Name the
web page LinkRotator, which NetBeans saves as NetBeans.html, and then
enter Listing 19.3 as the web page’s markup.

LISTING 19.2 Continued
Free download pdf