This is the simplest applet to animate an array of images. In the practice, you should the use of double-buffering (which this example does isn't use ) to eliminate flickering.
Import java.applet.*; Import java.awt.*; public classAnimappletExtends Applet implements Runnable {image[] images = new image[2]; int frame = 0; volatile thread thread; public void init () {images[0] = GetImage (Getdocumentbase (),"Http://hostname/image0.gif"); IMAGES[1] = GetImage (Getdocumentbase (),"Http://hostname/image1.gif"); public void Start () {(thread = new Thread (this)). Start (); } public void Stop () {thread = null; } public void Paint (Graphics g) {g.drawimage (Images[frame],0,0, this); } public void Run () {int delay = +; 1 second try {while (thread = = Thread.CurrentThread ()) {frame = (frame+1 )%images.length; Repaint (); Thread.Sleep (delay); }} catch (Exception e) {}}}
e558. Multi-image interactive display in applets