import java.applet.*;
import java.awt.*;
import java.util.Date;
public class ThreeClocksAppletT extends Applet 
{
static String t1,t2,t3;
Thread th1,th2,th3;
public void init()
{
t1="";
t2="";
t3="";
th1=new SimpleThread(1000);
th2=new SimpleThread(3000);
th3=new SimpleThread(5000);
th1.start();
th2.start();
th3.start();
}
public void paint(Graphics g)
{
g.drawString(t1,10,10);
g.drawString(t2,10,30);
g.drawString(t3,10,50);
}
}
class SimpleThread extends Thread
{
int num;
SimpleThread(int i)
{
super();
num=i;
}
public void run()
{
ThreeClocksAppletT th=new ThreeClocksAppletT();
while(true)
{
Date d=new Date();
String t=d.toString();
t=t.substring(11,19);
if(num==1000)
{
ThreeClocksAppletT.t1=t;
th.repaint();//为什么不好用?
}
else if(num==3000)
{
ThreeClocksAppletT.t2=t;
th.update();//为什么不好用?
}
else
{
ThreeClocksAppletT.t3=t;
th.update();//为什么不好用?
}
try
{
sleep(num);
}
catch(InterruptedException e){}
}
}
}