// Demonstrate a threaded applet 	
import java.awt.*;	
import java.util.*;	
import javax.swing.*;	
	
public class ClockApplet extends JApplet implements Runnable {	
    private Thread updateThread;	
    private String clockFace = "";	
	
    // init():  perform initialization 	
    public void init() {	
       updateThread = null;	
    }	
	
    // start():  start up the applet 	
    public void start() {	
       if (updateThread == null) {	
          updateThread = new Thread(this);	
          updateThread.start();	
       }	
    }	
	
    // run():  thread activity 	
    public void run() {	
        Thread me = Thread.currentThread();	
        while (updateThread == me) {	
           try {	
              me.sleep(1000);	
           }	
           catch (InterruptedException e) {	
              break;	
          }	
           repaint();	
        }	
    }	
	
    // paint(): issues the drawing and color setting requests 	
    public void paint(Graphics g) {	
       Date time = new Date();		
       g.setColor(Color.WHITE);		
       g.drawString(clockFace, 10, 20);		
       clockFace = time.toString();		
       g.setColor(Color.BLUE);		
       g.drawString(clockFace, 10, 20);		
    }	
	
    // stop(): all done 	
    public void stop() {	
       updateThread = null;	
    }	
}	
	
