import java.io.InputStream; import java.applet.Applet; import java.awt.*; import java.net.*; public class SimpleAnimate extends Applet implements Runnable { Image img[]; Thread duke = null; int nimg = 0; int x = 0; int frame = 0; // THESE COULD BE PASSED IN AS APPLET PARAMETERS int left_margin = 30; int top_margin = 20; int pause = 100; int move_right = 10; int total_frames= 50; public void init() { img = new Image[2]; img[0] = getImage(getDocumentBase(), "images/Simple/T1.gif"); img[1] = getImage(getDocumentBase(), "images/Simple/T2.gif"); } public void run() { while (duke != null) { frame++; nimg++; if (frame >= total_frames) frame = 0; if (nimg > 1) nimg = 0; x = left_margin + (frame * move_right); repaint(); try { Thread.sleep(pause); } catch (InterruptedException e) { break; } } } public void paint(Graphics g) { g.drawImage(img[nimg], x, top_margin, this); } public void start() { duke = new Thread(this); duke.start(); } public void stop() { duke.stop(); duke = null; } }