import java.util.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.text.*;

public class Clock3 extends Applet implements ActionListener {
	public void init() {
		Diag.threadPrint("init");

		setLayout(new FlowLayout(FlowLayout.CENTER));
		Label clock = new Label(simpleDateFormat.format(new Date(0)));
		add(clock);

		b = new Button("Pause");
		b.setForeground(Color.red);
		add(b);
		b.addActionListener(this);

		lapButton = new Button("Lap");
		lapButton.setForeground(Color.blue);
		add(lapButton);
		lapButton.addActionListener(this);

		lapList = new java.awt.List();
		add(lapList);

		clockThread = new Clock3Thread(clock);
		clockThread.start();
	}

	public void actionPerformed(ActionEvent e) {
		Diag.threadPrint("actionPerformed");
		if (e.getSource() == b) {
			boolean paused = clockThread.togglePaused();
			if (!paused) {
				b.setForeground(Color.red);
				b.setLabel("Pause");
			}
			else {
				b.setForeground(DARK_GREEN);
				b.setLabel("Resume");
			}
		}
		else
			lapList.add(simpleDateFormat.format(clockThread.getCurrentDuration()));
	}


	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mm:ss");
	static final Color DARK_GREEN = new Color(0, 100, 0);
	Button b, lapButton;
	Clock3Thread clockThread;
	java.awt.List lapList;
}

	