/* 
 * Copyright (c) 1999-2002, Xiaoping Jia.  
 * All Rights Reserved. 
 */

import java.awt.*;
import java.util.Calendar;

/**
 *  This is an applet that displays the time in the following format:
 *        HH:MM:SS
 */
public class DigitalClock
  extends java.applet.Applet implements Runnable {

  protected Thread clockThread = null;
  protected Font font = new Font("Monospaced", Font.BOLD, 48);
  protected Color color = Color.green;

  public void start() {
    if (clockThread == null) {
      clockThread = new Thread(this);
      clockThread.start();
    }
  }

  public void stop() {
    clockThread = null;
  }

  public void run() {
    while (Thread.currentThread()  ==  clockThread) {
      repaint();
      try {
	Thread.currentThread().sleep(1000);
      } catch (InterruptedException e) {}
    }
  }

  public void paint(Graphics g) {
    Calendar calendar = Calendar.getInstance();
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);
    g.setFont(font);
    g.setColor(color);
    g.drawString(hour + ":" + minute / 10 + minute % 10 +
                        ":" + second / 10 + second % 10, 10, 60);
  }

}