FileDocCategorySizeDatePackage
ClockApplet.javaAPI DocExample994Tue Nov 25 11:03:14 GMT 2003None

ClockApplet

public class ClockApplet extends Applet implements Runnable
An Applet to display the current time

Fields Summary
protected Thread
timerThread
A Thread to run the timer
Date
date
The date object
protected DateFormat
format
The date format
Constructors Summary
Methods Summary
public voidpaint(java.awt.Graphics g)
Display the time.

		date.setTime(System.currentTimeMillis());
		g.drawString(format.format(date), 2, 10);
	
public voidrun()
Show the time, and wait a while.

		while (timerThread != null) {
			repaint();	// request a redraw
			try {
				timerThread.sleep(1000);
			} catch (InterruptedException e){ /* do nothing*/ }
		}
	
public voidstart()


	/* Applet Lifestyle Methods */
	   
		timerThread = new Thread(this, "Clock");
		timerThread.start();
	
public voidstop()

		if (timerThread == null)
			return;
		timerThread = null;