home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap31
/
ThreadApplet3.java
< prev
next >
Wrap
Text File
|
1996-03-21
|
1KB
|
63 lines
import java.awt.*;
import java.applet.*;
import MyThread2;
public class ThreadApplet3 extends Applet
{
MyThread2 thread1;
MyThread2 thread2;
String displayStr;
Font font;
int position;
public void init()
{
font = new Font("TimesRoman", Font.PLAIN, 72);
setFont(font);
displayStr = "";
position = 120;
thread1 = new MyThread2(this, true);
thread2 = new MyThread2(this, false);
}
public void start()
{
if (thread1.isAlive())
thread1.resume();
else
thread1.start();
if (thread2.isAlive())
thread2.resume();
else
thread2.start();
}
public void stop()
{
thread1.suspend();
thread2.suspend();
}
public void destroy()
{
thread1.stop();
thread2.stop();
}
public void paint(Graphics g)
{
g.drawString(displayStr, 50, position);
}
synchronized public void SetDisplayStr(String str, int pos)
{
displayStr = str;
position = pos;
repaint();
}
}