import java.util.Date;
import java.applet.Applet;
import java.awt.*;
public class Horloge extends Applet implements Runnable {
volatile Thread timer; Font f; Color textColor;
public void init() {
f = new Font("Serif", Font.PLAIN, 14);
try {
int color = Integer.parseInt(getParameter("textcolor"),16);
textColor = new Color(color);
} catch (Exception e) {
textColor = Color.red; }
}
public void paint(Graphics g) {
String now = new Date().toString();
g.setFont(f);
g.setColor(textColor);
g.drawString(now, 50, 50);
}
public void start() {
timer = new Thread(this);
timer.start();
}
public void run() {
try {
Thread t = Thread.currentThread();
while (timer == t) { t.sleep(500);
repaint();
}
} catch (InterruptedException e) { }
}
public void stop() {
timer.interrupt();
}
public String getAppletInfo() {
return new String("Titre: Horloge \n" +
"Author: Etienne Duris, d'après Rachel Gollub\n" +
"Simple horloge textuelle.");
}
}