Package com.jgoodies.animation
Class Animator
- java.lang.Object
-
- com.jgoodies.animation.Animator
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.util.EventListener
public final class Animator extends java.lang.Object implements java.awt.event.ActionListener
Starts and stops an animation and triggers the animation at a given frame rate.- Version:
- $Revision: 1.8 $
-
-
Field Summary
Fields Modifier and Type Field Description private Animation
animation
private long
elapsedTime
private int
framesPerSecond
private long
startTime
private javax.swing.Timer
timer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
Implements the ActionListener interface used by the Timer.Animation
animation()
Returns the animator's animation.private javax.swing.Timer
createTimer(int fps)
Creates and configures aTimer
object.long
elapsedTime()
Returns the elapsed time since animation start.int
framesPerSecond()
Returns the desired frame rate.private void
registerStopListener()
Registers a listener that stops the animator if the animation stopped.void
start()
Starts the animator and in turn the animation.void
stop()
Stops the animator.java.lang.String
toString()
Returns a string representation for the animator.
-
-
-
Field Detail
-
animation
private final Animation animation
-
timer
private final javax.swing.Timer timer
-
framesPerSecond
private final int framesPerSecond
-
startTime
private long startTime
-
elapsedTime
private long elapsedTime
-
-
Constructor Detail
-
Animator
public Animator(Animation animation, int framesPerSecond)
Constructs an Animator for the given animation and frame rate.- Parameters:
animation
- the animation to animateframesPerSecond
- the desired frame rate- Throws:
java.lang.NullPointerException
- if the animation isnull
java.lang.IllegalArgumentException
- if the frame rate is non-positive
-
-
Method Detail
-
animation
public Animation animation()
Returns the animator's animation.- Returns:
- the animator's animation
-
framesPerSecond
public int framesPerSecond()
Returns the desired frame rate.- Returns:
- the desired frame rate per second
-
elapsedTime
public long elapsedTime()
Returns the elapsed time since animation start.- Returns:
- time elapsed since the animation start
-
start
public void start()
Starts the animator and in turn the animation.
-
stop
public void stop()
Stops the animator.
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Implements the ActionListener interface used by the Timer.- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
e
- the action event
-
toString
public java.lang.String toString()
Returns a string representation for the animator.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation for the animator
-
createTimer
private javax.swing.Timer createTimer(int fps)
Creates and configures aTimer
object.- Parameters:
fps
- the frames per second- Returns:
- a
Timer
with the specified frame rate
-
registerStopListener
private void registerStopListener()
Registers a listener that stops the animator if the animation stopped.
-
-