/* Rotator - an applet that animates a sequence of frames stored as a horizontal strip in a single image. http://rsb.info.nih.gov/nih-image/Java/Rotator/ Parameters: image Name of image file, no default rate Rate in frames per second, default = "6" bgcolor Background color, default = "ffffff" (white) This example animates 10 55x68 frames stored in a single 550x68 gif file. */ import java.awt.* ; public class Rotator extends java.applet.Applet implements Runnable { int frameWidth; int delay = 167; // milliseconds (6 frames/sec) int frame = 0; int bgcolor = 0xffffff; //white boolean suspended = false; Thread runThread; Image img; public void init() { String p = getParameter("width"); frameWidth = Integer.parseInt(p); p = getParameter("rate"); if (p != null) delay = 1000 / Integer.parseInt(p); if (delay < 10) delay = 10; p = getParameter("bgcolor"); if (p != null) bgcolor = Integer.parseInt(p, 16); setBackground(new Color(bgcolor)); img = getImage(getCodeBase(), getParameter("image")); } public void start() { if (runThread == null) { runThread = new Thread (this); runThread.start(); } } public void run() { while (runThread != null) { repaint(); try {runThread.sleep(delay);} catch (InterruptedException e) { } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(img, -frame * frameWidth, 0, null); if (++frame == img.getWidth(this) / frameWidth) frame = 0; } public boolean mouseDown(Event evt, int x, int y) { if (suspended) runThread.resume(); else runThread.suspend(); suspended = !suspended; return true; } public void stop() { if (runThread != null) { runThread.stop(); runThread = null; } } }// Rotator