1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import java.applet.Applet; import java.awt.Graphics; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class TimeApplet extends Applet implements Runnable { private DateFormat formatter = null; private Thread t = null; public void init() { formatter = new SimpleDateFormat("hh:mm:ss"); t = new Thread(this); } public void start() { t.start(); } public void stop() { t = null; } public void paint(Graphics g) { Date now = Calendar.getInstance().getTime(); // // Show the current time on the browser status bar // this.showStatus(formatter.format(now)); } public void run() { int delay = 1000; try { while (t == Thread.currentThread()) { // // Repaint the applet every on second // repaint(); Thread.sleep(delay); } } catch (Exception e) { e.printStackTrace(); } } } |