import java.awt.Graphics; import java.applet.Applet; import java.util.Date; public class HelloWorldClockApplet extends Applet implements Runnable { Thread thread = null;; // paintメソッドをオーバーライド public void paint(Graphics g) { // 現在の時刻を座標(20,20)の位置に描画 Date now = new Date(); g.drawString(now.toString() , 20, 20); } // startメソッドをオーバーライド public void start() { if (thread==null) { // スレッドを生成 thread = new Thread(this); // スレッドを開始 thread.start(); } } // stopメソッドをオーバーライド public void stop() { // スレッド終了 thread = null; } // スレッドの処理 public void run() { while (thread!=null) { // 再描画します repaint(); try { // スレッドを1000ミリ秒停止します thread.sleep(1000); } catch (InterruptedException e) { } } } }