// import java.awt.event.*; import java.awt.*; public class LadyBugPop extends java.applet.Applet implements Runnable { Image bugimg; Thread runner; int scale; Image offscreenImage; Graphics offscreenGraphics; Dimension offscreenSize; public void init() { MediaTracker tracker = new MediaTracker(this); bugimg = getImage(getCodeBase(), "ladybug.gif"); tracker.addImage(bugimg, 1); try { tracker.waitForAll(); if (tracker.isErrorAny()) System.out.println("Error loading image"); else System.out.println("Image loaded..."); } catch (Exception e) { e.printStackTrace(); } } public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { runner = null; } public void run() { while (runner != null) { for (scale = 10; scale > 0; scale--) { showStatus("scale: " + scale + "0%"); repaint(); try { runner.sleep(200); } catch (InterruptedException e) {} } for (scale = 1; scale <= 10; scale++) { showStatus("scale: " + scale + "0%"); repaint(); try { runner.sleep(200); } catch (InterruptedException e) {} } } } public void update(Graphics g) { Dimension d = getSize(); if ((offscreenImage == null) || (d.width != offscreenSize.width) || (d.height != offscreenSize.height)) { offscreenImage = createImage(d.width, d.height); offscreenSize = d; offscreenGraphics = offscreenImage.getGraphics(); } offscreenGraphics.clearRect(0, 0, d.width, d.height); paint(offscreenGraphics); g.drawImage(offscreenImage, 0, 0, null); } public void destroy() { offscreenGraphics.dispose(); } public void paint(Graphics g) { // helps show the double buffering setBackground(Color.red); if (runner != null) { g.drawImage(bugimg, 0, 0, bugimg.getWidth(this) * scale / 10, bugimg.getHeight(this) * scale / 10, this); } } }