import java.awt.*;
import java.applet.*;
import java.util.*;
public class Clock extends Applet implements Runnable {
private boolean runFlag;
private Thread t = null;
private String otime = "";
public void start() {
if (t == null) {
t = new Thread (this);
t.start();
}
}
public void stop() {
if (t != null) {
runFlag=false;
t=null;
}
}
public void run () {
runFlag=true;
while (runFlag) {
repaint();
try { Thread.sleep(1000); }
catch (InterruptedException e) {}
}
}
public void update (Graphics g) {
paint(g);
}
public void paint (Graphics g) {
Date today = new Date();
String hours = today.getHours() + "";
String minutes = today.getMinutes() + "";
if(today.getMinutes()<10) {
minutes = "0" + minutes;
}
String seconds = today.getSeconds() + "";
if(today.getSeconds()<10) {
seconds = "0" + seconds;
}
String time = "Zeit: " + hours + ":" + minutes + ":" + seconds;
g.setColor(Color.white);
g.drawString( otime, 30, 30 );
g.setColor(Color.black);
g.drawString( time, 30, 30 );
otime = time;
}
}