/* 
 * 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 DigitalClock1b
  extends java.applet.Applet implements Runnable {

  protected Thread clockThread = null;
  protected Font font = new Font("Monospaced", Font.BOLD, 24);
  protected Color color = Color.green;
  int time = 0;

  public void start() {
    if (clockThread == null) {
      clockThread = new Thread(this);
      clockThread.start();
    }
    time = 0;
 
  }

  public void stop() {
    clockThread = null;
  }

  public void run() {
    while (Thread.currentThread()  ==  clockThread) {
      repaint();
      try {
	Thread.currentThread().sleep(1000);
	time++; 
      } 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);
    g.drawString(threadInfo(Thread.currentThread()), 10, 100);
  }

    String threadInfo(Thread t) {
        return "thread=" + t.getName() + ", "
               + "thread group=" + t.getThreadGroup().getName();
    }

}
