// An application to show scratching import java.awt.*; import java.awt.event.*; public class ScratchFrame extends Frame { Image scratch1, scratch2, currentpic; int xpos = 50; int ypos = 50; void pause(int time) { try { Thread.sleep(time); } catch (InterruptedException e) { } } public void init() { this.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { System.exit(0); } public void windowClosing(WindowEvent e) { System.exit(0); } }); // get the images from the image folder: Toolkit toolkit = Toolkit.getDefaultToolkit(); scratch1 = toolkit.getImage("images/scratch1.gif"); scratch2 = toolkit.getImage("images/scratch2.gif"); } public void run() { setBackground(Color.white); repaint(); scratch(200); } public void scratch(int numtimes) { currentpic = scratch1; repaint(); pause(150); currentpic = scratch2; repaint(); pause(150); if (numtimes == 0); // we are done -- do nothing else scratch(numtimes-1); } public void paint(Graphics g) { if (currentpic != null) g.drawImage(currentpic, xpos, ypos, this); } public static void main(String[] args) { ScratchFrame n = new ScratchFrame(); n.setSize(200,200); n.setVisible(true); n.init(); n.run(); } }