Original Post
import java.awt.*;
import java.applet.*;
public class Test extends Applet implements Runnable {
int nr = 0;
Thread thread;
Dimension d;
public void init() {
d = size();
}
public void run() {
long starttime;
Graphics g;
g=getGraphics();
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
while(true) {
starttime=System.currentTimeMillis();
try {
paint(g);
starttime += 30;
nr++;
Thread.sleep(Math.max(0, starttime-System.currentTimeMillis()));
}
catch (InterruptedException e) {
break;
}
}
}
public void start() {
if (thread == null) {
thread = new Thread(this);
thread.start();
}
}
public void stop() {
if (thread != null) {
thread.stop();
thread = null;
}
}
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.fillRect(0,0,d.width,d.height);
g.setColor(Color.MAGENTA);
g.drawString(nr, 10, 10);
}
}