FileDocCategorySizeDatePackage
ImageSequenceTimer.javaAPI DocExample4124Tue Dec 12 18:59:04 GMT 2000None

ImageSequenceTimer

public class ImageSequenceTimer extends JApplet implements ActionListener

Fields Summary
ImageSQPanel
imageSQPanel
static int
frameNumber
int
delay
Thread
animatorThread
static boolean
frozen
Timer
timer
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

        //Advance the animation frame.
        frameNumber++;

        //Display it.
        imageSQPanel.repaint();
    
voidbuildUI(java.awt.Container container, java.awt.Image[] dukes)

        int fps = 10;

        //How many milliseconds between frames?
        delay = (fps > 0) ? (1000 / fps) : 100;

        //Set up a timer that calls this object's action handler
        timer = new Timer(delay, this);
        timer.setInitialDelay(0);
        timer.setCoalesce(true);

        imageSQPanel = new ImageSQPanel(dukes);
        container.add(imageSQPanel, BorderLayout.CENTER);
 
        imageSQPanel.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                if (frozen) {
                    frozen = false;
                    startAnimation();
                } else {
                    frozen = true;
                    stopAnimation();
                }
            }
       });
    
public voidinit()


    //Invoked only when this is run as an applet.
       
        //Get the images.
        Image[] images = new Image[10];
        for (int i = 1; i <= 10; i++) {
            images[i-1] = getImage(getCodeBase(), "images/T"+i+".gif");
        }
        buildUI(getContentPane(), images);
        startAnimation();
    
public static voidmain(java.lang.String[] args)

        Image[] waving = new Image[10];

        for (int i = 1; i <= 10; i++) {
            waving[i-1] = 
                Toolkit.getDefaultToolkit().getImage(
                    "images/T"+i+".gif"); 
        }

        JFrame f = new JFrame("ImageSequenceTimer");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        ImageSequenceTimer controller = new ImageSequenceTimer();
        controller.buildUI(f.getContentPane(), waving);
        controller.startAnimation();
        f.setSize(new Dimension(75, 100));
        f.setVisible(true);
    
public voidstart()

        startAnimation();
    
public synchronized voidstartAnimation()

        if (frozen) { 
            //Do nothing.  The user has requested that we 
            //stop changing the image.
        } else {
            //Start animating!
            if (!timer.isRunning()) {
                timer.start();
            }
        }
    
public voidstop()

        stopAnimation();
    
public synchronized voidstopAnimation()

        //Stop the animating thread.
        if (timer.isRunning()) {
            timer.stop();
        }