import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class DigitalClock3 extends AnimationApplet implements ItemListener {
  public DigitalClock3() {
    setDelay(1000);
  }

  public void init() {
    setLayout(new BorderLayout());

    // Add all the time zone description on the computer into a choice list.
    southPanel.setLayout(new FlowLayout());
    TimeZone timeZone=TimeZone.getDefault();
    String[] timeZoneIDs=timeZone.getAvailableIDs();
    for (int i=0; i<timeZoneIDs.length; i++) {
      timeZoneChoice.add(timeZoneIDs[i]);
    }

    String currentTimeZone=timeZone.getID();
    timeZoneChoice.select(currentTimeZone);
    timeZoneChoice.addItemListener(this);
    southPanel.add(timeZoneChoice);

    add("South", southPanel);
  }

  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, 80);
  }

  public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange()==e.SELECTED) {
      // When a new timezone is selected, change the default timezone to the new one.
      String newTimeZoneID=(String) e.getItem();
      TimeZone.setDefault(TimeZone.getTimeZone(newTimeZoneID));
    }
  }

  protected Font font = new Font("Monospaced", Font.BOLD, 48);
  protected Color color = Color.green;
  protected Panel southPanel=new Panel();
  protected Choice timeZoneChoice=new Choice();
}

