Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent e)
//Advance animation frame.
frameNumber++;
//Display it.
animationPane.repaint();
|
void | buildUI(java.awt.Container container, java.awt.Image bgImage, java.awt.Image fgImage)
int fps = 10;
//How many milliseconds between frames?
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);
animationPane = new AnimationPane(bgImage, fgImage);
container.add(animationPane, BorderLayout.CENTER);
animationPane.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (frozen) {
frozen = false;
startAnimation();
} else {
frozen = true;
stopAnimation();
}
}
});
|
public void | init()
//Invoked only when run as an applet.
//Get the images.
Image bgImage = getImage(getCodeBase(), bgFile);
Image fgImage = getImage(getCodeBase(), fgFile);
buildUI(getContentPane(), bgImage, fgImage);
|
public static void | main(java.lang.String[] args)
Image bgImage = Toolkit.getDefaultToolkit().getImage(
MovingImageTimer.bgFile);
Image fgImage = Toolkit.getDefaultToolkit().getImage(
MovingImageTimer.fgFile);
JFrame f = new JFrame("MovingImageTimer");
final MovingImageTimer controller = new MovingImageTimer();
controller.buildUI(f.getContentPane(), bgImage, fgImage);
f.addWindowListener(new WindowAdapter() {
public void windowIconified(WindowEvent e) {
controller.stopAnimation();
}
public void windowDeiconified(WindowEvent e) {
controller.startAnimation();
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setSize(new Dimension(500, 125));
f.setVisible(true);
controller.startAnimation();
|
public void | start()
startAnimation();
|
public synchronized void | startAnimation()
if (frozen) {
//Do nothing. The user has requested that we
//stop changing the image.
} else {
//Start animating!
if (!timer.isRunning()) {
timer.start();
}
}
|
public void | stop()
stopAnimation();
|
public synchronized void | stopAnimation()
//Stop the animating thread.
if (timer.isRunning()) {
timer.stop();
}
|