import java.util.Date;
import java.awt.Graphics;
public class Example10_2 extends java.applet.Applet implements Runnable{
	Thread clockThread;
	public void start(){
		if (clockThread == null){
			clockThread = new Thread(this, "Clock");       //创建线程实例
			clockThread.start();                        //启动执行
}
}
public void run( ) {                                   //定义线程体
		 while (clockThread != null){
			repaint();
			try{
				clockThread.sleep(1000);
			}catch (InterruptedException e){}
		 }
	   } 
	   public void paint(Graphics g) {
		 Date now = new Date();                   //获取当前系统时间
		 g.drawString(now.toString(), 5, 10);
	   }
	   public void stop(){
      	 clockThread.stop();                      
		 clockThread = null;
	   } 
 }
