import java.applet.*; import java.awt.*; public class main extends Applet implements Runnable { final int W = 320, H = 240, IMAGECOUNT = 51; Graphics backBuffer = null; Image images[] = null, offscreen = null; MediaTracker mt = null; Thread th = null; int currentIndex = 0; public void init() { this.setBackground(Color.WHITE); this.setSize(W,H); images = new Image[IMAGECOUNT]; mt = new MediaTracker(this); for (int i=0; i < IMAGECOUNT; i++) { images[i] = this.getImage(this.getCodeBase(),"seq/img"+i+".jpg"); mt.addImage(images[i],i); } offscreen = this.createImage(W,H); backBuffer = offscreen.getGraphics(); } public void start() { th = new Thread(this); th.start(); } public void run() { try { mt.waitForAll(); } catch (InterruptedException ie) { System.err.println("MediaTracker : Interrupted!"); return; } while (th != null) { if (currentIndex < IMAGECOUNT-1) currentIndex ++; else currentIndex = 0; repaint(); try { th.sleep(30); } catch (InterruptedException e) {} } } public void stop() { th.stop(); th = null; } public void paint (Graphics g) { backBuffer.drawImage(images[currentIndex], 0,0, this); g.drawImage(offscreen, 0,0, this); } public void update (Graphics g) { paint(g); } }