import java.awt.*; public class Checker extends java.applet.Applet implements Runnable { Thread runner; int xpos,ux1,ux2; Image offscreenImg; Graphics offscreenG; public void Init() { offscreenImg = createImage(this.size().width,this.size().height); offscreenG = offscreenImg.getGraphics(); } public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { if (runner != null) { runner.stop(); runner = null; } } public void run() { setBackground(Color.blue); while (true) { for (xpos=5; xpos<=105; xpos+=4) { ux2 = xpos + 90; repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { } if (ux1 == 0) ux1 = xpos-1; } for (xpos=105; xpos>=5; xpos-=4) { ux1 = xpos; repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { } if (ux2 == 0) ux2 = xpos + 91; } } } public void update(Graphics g) { g.clipRect(ux1, 5, (ux2-ux1), 90); paint(g); } public void paint(Graphics g) { // Draw background offscreenG.setColor(Color.white); offscreenG.fillRect(101,0,100,100); offscreenG.setColor(Color.black); offscreenG.fillRect(0,0,100,100); // Draw checker offscreenG.setColor(Color.red); offscreenG.fillOval(xpos,5,90,90); // Reset the drawing area. ux1 = ux2 = 0; // Display the image. g.drawImage(offscreenImg,0,0,this); } }