Package ch.swingfx.timer
Class AnimationTimer
- java.lang.Object
-
- ch.swingfx.timer.AnimationTimer
-
public class AnimationTimer extends java.lang.ObjectClass for simple animation. Example:
AnimationTimer at = new AnimationTimer(FrameRate.FPS_25); at.setDuration(2500); // 2500 milliseconds at.setAnimationTarget(new AnimationTarget() { public void event(AnimationTimer timer, float fraction) { // between begin and end. // fraction represents the time passed (0f = 0%, 1f = 100%) } public void begin(AnimationTimer timer) { // start of the animation } public void end(AnimationTimer timer) { // end of the animation } }); at.start();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAnimationTimer.AnimationTargetUsed withAnimationTimer.setAnimationTarget().
Implement this interface to receive events from theAnimationTimerstatic classAnimationTimer.FrameRateFrame rates for theAnimationTimer
Note: These frame rates are approximations.private classAnimationTimer.TimerActionListenerHandles the calculation of the time that has elapsed since the start and sends it to theAnimationTimer.AnimationTarget
-
Field Summary
Fields Modifier and Type Field Description private longfAnimationStartTimeStores the start time of the animation so we can calculate the fractionprivate AnimationTimer.AnimationTargetfAnimationTargetAnimation events get sent to this targetprivate longfDurationDuration of the animation in millisecondsprivate javax.swing.TimerfTimerThe timer for the animation
-
Constructor Summary
Constructors Constructor Description AnimationTimer()Creates anAnimationTimerwith a default frame rate of 25AnimationTimer(AnimationTimer.FrameRate fps)Creates anAnimationTimerwith an specified frame rate
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsetAnimationTarget(AnimationTimer.AnimationTarget target)Set the animation targetvoidsetDuration(long duration)Set the duration of the animationvoidstart()Start the animationvoidstop()End the animation before duration has passed
-
-
-
Field Detail
-
fTimer
private final javax.swing.Timer fTimer
The timer for the animation
-
fAnimationTarget
private AnimationTimer.AnimationTarget fAnimationTarget
Animation events get sent to this target
-
fAnimationStartTime
private long fAnimationStartTime
Stores the start time of the animation so we can calculate the fraction
-
fDuration
private long fDuration
Duration of the animation in milliseconds
-
-
Constructor Detail
-
AnimationTimer
public AnimationTimer()
Creates anAnimationTimerwith a default frame rate of 25
-
AnimationTimer
public AnimationTimer(AnimationTimer.FrameRate fps)
Creates anAnimationTimerwith an specified frame rate- Parameters:
fps-AnimationTimer.FrameRatewe want to use for thisAnimationTimer
-
-
Method Detail
-
setDuration
public void setDuration(long duration)
Set the duration of the animation- Parameters:
duration- the duration of the animation
-
start
public void start()
Start the animation
-
stop
public void stop()
End the animation before duration has passed
-
setAnimationTarget
public void setAnimationTarget(AnimationTimer.AnimationTarget target)
Set the animation target- Parameters:
target- the animation target
-
-