import java.awt.*;
import java.util.*;
import java.text.*;

class Clock3Thread extends Thread {
	Clock3Thread(Label clock) {this.clock = clock;}

	boolean togglePaused() {
		Diag.threadPrint("togglePaused");	
		paused = !paused;
		return paused;
	}

	public void run() {
		Diag.threadPrint("run");
		startDate = new Date();
		int count = 0;
		while (true) {
			if (!paused) {
				Date duration = new Date(new Date().getTime() - startDate.getTime());
				clock.setText(simpleDateFormat.format(duration));
				count++;
				if (count > 10) {
					Diag.threadPrint("tick");
					count = 0;
				}
			}
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
			}
		}
	}

	Date getCurrentDuration() {
		return new Date(new Date().getTime() - startDate.getTime());
	}


	Date startDate;
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mm:ss");
	boolean paused = false;
	Label clock;
}
