FileDocCategorySizeDatePackage
Animator.javaAPI DocExample2482Thu Aug 08 12:25:50 BST 1996None

Animator

public class Animator extends Applet implements Runnable
This applet displays an animation. It doesn't handle errors while loading images. It doesn't wait for all images to be loaded before starting the animation. These problems will be addressed later.

Fields Summary
protected Image[]
images
protected int
current_image
private Thread
animator_thread
Constructors Summary
Methods Summary
public voidinit()

        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);
        }
    
public voidrun()

        while(true) {
            if (++current_image >= images.length) current_image = 0;
            this.getGraphics().drawImage(images[current_image], 0, 0, this);
            this.getToolkit().sync();  // Force it to be drawn *now*.
            try { Thread.sleep(200); } catch (InterruptedException e) { ; }
        }
    
public voidstart()

       
        if (animator_thread == null) {
            animator_thread = new Thread(this);
            animator_thread.start();
        }
    
public voidstop()

        if ((animator_thread != null) && animator_thread.isAlive()) 
            animator_thread.stop();
        // We do this so the garbage collector can reclaim the Thread object.
        // Otherwise it might sit around in the Web browser for a long time.
        animator_thread = null;