FileDocCategorySizeDatePackage
AnimatorAppletTimer.javaAPI DocExample2448Tue Dec 12 18:59:06 GMT 2000None

AnimatorAppletTimer

public class AnimatorAppletTimer extends JApplet implements ActionListener

Fields Summary
int
frameNumber
Timer
timer
boolean
frozen
JLabel
label
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

        //Advance the animation frame.
        frameNumber++;

        //Request that the frame be painted.
        label.setText("Frame " + frameNumber);
    
public voidinit()


       
        String str;
        int fps = 0;

        //How many milliseconds between frames?  
        str = getParameter("fps");
        try { 
            if (str != null) {
                fps = Integer.parseInt(str);
            }
        } catch (Exception e) {}

        int 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);

        label = new JLabel("Frame   ", JLabel.CENTER);

        label.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                if (frozen) {
                    frozen = false;
                    startAnimation();
                } else {
                    frozen = true;
                    stopAnimation();
                }
            }
        });

        getContentPane().add(label, BorderLayout.CENTER);
    
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();
        }