/* test Date repaint */ import java.awt.*; import java.applet.*; import java.util.Date; public class DateRun extends Applet implements Runnable { private String explain = "Runnable, each second repaint updates time"; private Thread timer = null; // our applet's thread public void init() { setFont(new Font("TimesRoman",Font.BOLD,20)); } public void start() { if(timer == null) { timer = new Thread(this); timer.start(); } } public void stop() { timer = null; } public void paint(Graphics g) { Date now = new Date(); // current date and time g.drawString(now.toString(), 5,20); g.drawString(explain,10,40); } public void run() { // repaint once a second while (timer != null) { try {Thread.sleep(1000);} catch (InterruptedException e){} repaint(); } } public boolean running() {return true;} // always running }