// animator applet import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; public class Animator extends Applet implements Runnable { protected Image[] images; protected int current_image; // Read basename and num_images parameters. // Then read in images. public void init() { String basename = this.getParameter("basename"); int num_images; try { num_images = Integer.parseInt(this.getParameter("num_images")); } catch (NumberFormatException e) { num_images = 0; } images = new Image[num_images]; for (int i = 0; i < num_images; i++) { images[i] = this.getImage(this.getDocumentBase(), basename + i + ".gif"); } } // thread that runs animation private Thread animator_thread = null; public void start() { if (animator_thread == null) { animator_thread = new Thread(this); animator_thread.start(); } } public void stop() { if ((animator_thread != null) && animator_thread.isAlive()) { animator_thread.stop(); } animator_thread = null; } public void run() { while(true) { if (++current_image >= images.length) current_image = 0; this.getGraphics().drawImage(images[current_image], 0, 0, this); try { Thread.sleep(300); } catch (InterruptedException e) {} } } }