home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Web Programming with Visual J++
/
Web_Programming_with_Visual_J_SAMS.NET_Version_1.0_1997.iso
/
source
/
chap12
/
ex12a.java
< prev
next >
Wrap
Text File
|
1996-09-22
|
1KB
|
62 lines
import java.applet.*;
import java.awt.*;
public class EX12A extends Applet implements Runnable
{
protected Thread CounterThread;
protected Label CountLabel;
protected int count = 10;
public void init()
{
// provide something to look at
add(new Label("Count:"));
CountLabel = new Label(Integer.toString(count));
add(CountLabel);
}
public void start()
{
if (CounterThread == null) {
// allocate the thread, using the local run method
CounterThread = new Thread(this);
CounterThread.start();
}
}
public void stop()
{
if (CounterThread != null) {
// stop the thread
CounterThread.stop();
CounterThread = null;
}
}
public void run()
{
while (true) {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {}
CountDown();
}
}
protected void CountDown()
{
count--;
CountLabel.setText(Integer.toString(count));
if (count == 0)
// reset to 11 since the first call will move it back
// down to 10 and then display
count = 11;
}
}