home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap31
/
ThreadApplet4.java
< prev
next >
Wrap
Text File
|
1996-03-21
|
1KB
|
64 lines
import java.awt.*;
import java.applet.*;
public class ThreadApplet4 extends Applet
implements Runnable
{
Thread thread;
int count;
String displayStr;
Font font;
public void init()
{
font = new Font("TimesRoman", Font.PLAIN, 72);
setFont(font);
count = 0;
displayStr = "";
thread = new Thread(this);
}
public void start()
{
if (thread.isAlive())
thread.resume();
else
thread.start();
}
public void stop()
{
thread.suspend();
}
public void destroy()
{
thread.stop();
}
public void run()
{
while (count < 1000)
{
++count;
displayStr = String.valueOf(count);
repaint();
try
{
thread.sleep(100);
}
catch (InterruptedException e)
{
}
}
}
public void paint(Graphics g)
{
g.drawString(displayStr, 50, 130);
}
}