Java Reference
In-Depth Information
Figure 23.1 The counter applet as it appears in a browser
<body>
<h2>This is the counter applet.</h2>
<APPLET CODE="its.Applet.CounterApplet.class" WIDTH="200" HEIGHT="100">
</APPLET>
</body>
</html>
The page is placed in the directory right above the its directory which contains
the class files. This page can also be reached from the topic's home page. You can
follow the link to the applet from there or type the following line in your browser
to load the page and run the applet. The result is shown in Figure 23.1.
http://www.imm.dtu.dk/swingbook/AppletTest/CounterDemo.html
23.1.2
An applet running a thread
The second example is an applet displaying a timer which is incremented every
half second. The timer is run in a thread of type TimerThread in order to avoid
blocking the applet. A panel ( TimerPanel )isused to display the current value
of the timer. The thread updates the panel every half second. The applet class is
called TimerApplet . The listings are shown below.
File: its/Applet/TimerThread.java
1. package its.Applet;
2.
3. public class TimerThread extends Thread {
4.
Search WWH ::




Custom Search