import java.awt.*; import java.applet.*; public class SafariBug extends Applet implements Runnable { Thread thread; int repaints; int paints; int updates; int idles; volatile boolean updating; Font font = new Font("Fixed", Font.BOLD, 36); public void start() { thread = new Thread(this); thread.start(); } public void stop() { thread = null; } public void run() { try { Thread thisThread = Thread.currentThread(); while (thisThread == thread) { setUpdating(true); ++repaints; repaint(); do { ++idles; thisThread.sleep(500); } while (getUpdating() && (thread != null)); } } catch (InterruptedException ex) { } } private synchronized boolean getUpdating() { return updating; } private synchronized void setUpdating(boolean b) { updating = b; } public void paint(Graphics g) { ++paints; update(g); } public void update(Graphics g) { ++updates; g.setColor(Color.blue); g.fillRect(0,0,size().width,size().height); g.setColor(Color.red); g.setFont(font); g.drawString("Paint: "+paints, 0, 30); g.drawString("Repaint: "+repaints, 0, 110); g.drawString("Update: "+updates, 0, 190); g.drawString("Idle: "+(idles-repaints), 0, 270); setUpdating(false); } public boolean mouseDown(Event ev,int x,int y) { getAppletContext().showStatus("p="+paints+" r="+repaints+" u="+updates+" i="+(idles-repaints)); return true; } }