// Clock.java Steve Tanimoto, 25 October 2000. import java.awt.*; import java.applet.*; import java.util.*; public class Clock extends Applet implements Runnable { class TimeThread extends Thread { boolean timeToQuit = false; public TimeThread(Runnable r) { super(r); } } TimeThread timeThread; public Clock() { } public void init() { timeThread = new TimeThread(this); timeThread.start(); } public void paint(Graphics g) { g.drawString("The time is: " + (new Date()), 100, 50); } public void run() { while (true) { try { Thread.sleep(1000); } catch (InterruptedException e) { if (timeThread.timeToQuit) return; } repaint(); } } public void start() {} public void stop() {} public void destroy() { timeThread.timeToQuit = true; timeThread.interrupt(); } }