Top Description Fields Constructors Methods
org.reactfx.util

public Class FxTimer

extends Object
implements Timer
Class Inheritance
All Implemented Interfaces
org.reactfx.util.Timer
Imports
javafx.animation.Animation, .KeyFrame, .Timeline, javafx.util.Duration

Provides factory methods for timers that are manipulated from and execute their action on the JavaFX application thread.

Field Summary

Modifier and TypeField and Description
private final Runnable
private final Duration
private long
private final Timeline

Constructor Summary

AccessConstructor and Description
private
FxTimer(Duration actionTime, Duration period, Runnable action, int cycles)

Method Summary

Modifier and TypeMethod and Description
public static Timer
create(Duration delay, Runnable action)

Prepares a (stopped) timer that lasts for delay and whose action runs when timer ends.

public static Timer
createPeriodic(Duration interval, Runnable action)

Prepares a (stopped) timer that lasts for interval and that executes the given action periodically when the timer ends.

public static Timer
createPeriodic0(Duration interval, Runnable action)

Prepares a (stopped) timer that lasts for interval and that executes the given action periodically when the timer starts.

public void
restart()

Implements org.reactfx.util.Timer.restart.

Schedules the associated action to be executed after the associated delay.

public static Timer
runLater(Duration delay, Runnable action)

Equivalent to create(delay, action).restart().

public static Timer
runPeriodically(Duration interval, Runnable action)

Equivalent to createPeriodic(interval, action).restart().

public static Timer
runPeriodically0(Duration interval, Runnable action)

Equivalent to createPeriodic0(interval, action).restart().

public void
stop()

Implements org.reactfx.util.Timer.stop.

If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actionback to summary
private final Runnable action
actionTimeback to summary
private final Duration actionTime
seqback to summary
private long seq
timelineback to summary
private final Timeline timeline

Constructor Detail

FxTimerback to summary
private FxTimer(Duration actionTime, Duration period, Runnable action, int cycles)

Method Detail

createback to summary
public static Timer create(Duration delay, Runnable action)

Prepares a (stopped) timer that lasts for delay and whose action runs when timer ends.

createPeriodicback to summary
public static Timer createPeriodic(Duration interval, Runnable action)

Prepares a (stopped) timer that lasts for interval and that executes the given action periodically when the timer ends.

createPeriodic0back to summary
public static Timer createPeriodic0(Duration interval, Runnable action)

Prepares a (stopped) timer that lasts for interval and that executes the given action periodically when the timer starts.

restartback to summary
public void restart()

Implements org.reactfx.util.Timer.restart.

Doc from org.reactfx.util.Timer.restart.

Schedules the associated action to be executed after the associated delay. If the action is already scheduled but hasn't been executed yet, the timeout is reset, so that the action won't be executed before the full delay from now.

Annotations
@Override
runLaterback to summary
public static Timer runLater(Duration delay, Runnable action)

Equivalent to create(delay, action).restart().

runPeriodicallyback to summary
public static Timer runPeriodically(Duration interval, Runnable action)

Equivalent to createPeriodic(interval, action).restart().

runPeriodically0back to summary
public static Timer runPeriodically0(Duration interval, Runnable action)

Equivalent to createPeriodic0(interval, action).restart().

stopback to summary
public void stop()

Implements org.reactfx.util.Timer.stop.

Doc from org.reactfx.util.Timer.stop.

If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all. This is also true in case the timer's timeout has already expired, but the associated action hasn't had a chance to be executed on the associated thread. Note that this is a stronger guarantee than the one given by javafx.animation.Animation#stop():

Timeline timeline = new Timeline(new KeyFrame(
        Duration.millis(1000),
        ae -> System.out.println("FIRED ANYWAY")));
timeline.play();

// later on the JavaFX application thread,
// but still before the action has been executed
timeline.stop();

// later, "FIRED ANYWAY" may still be printed

In contrast, using the FxTimer, the action is guaranteed not to be executed after stop():
Timer timer = FxTimer.runLater(
        Duration.ofMillis(1000),
        () -> System.out.println("FIRED"));

// later on the JavaFX application thread,
// but still before the action has been executed
timer.stop();

// "FIRED" is guaranteed *not* to be printed

Annotations
@Override