/* An applet that puts a clock in the window
*/
import java.awt.*;
import java.applet.Applet;
import java.util.*;
import java.text.*;

public class TrivialApplet extends Applet implements Runnable {
    private final static int SIZE= 8;        // Number of chars in clock
    private final static int DELAY= 1000;    // Millisconds to sleep -1 second
    private TextField clock;                 // The clock itself
    private Thread timer;                    // The thread that will run the clock
    
	public void init() {
		clock= new TextField(SIZE);
		add(clock);
	}
	
	public void start() {
	    timer= new Thread(this);
	    timer.start();
	}   
	
	public void stop() {
	    timer= null;
	}
	
	public void run() {
	    Date time;  // contains current time
	    SimpleDateFormat f= new SimpleDateFormat("h:mm:ss a");
	    while (timer != null) {
	        time= new Date();
	        clock.setText(f.format(time));
	        try {
	            Thread.currentThread().sleep(DELAY);
	        }
	        catch (InterruptedException e) {}
	    }
	}
}

