Class FxTimer
java.lang.Object
org.reactfx.util.FxTimer
- All Implemented Interfaces:
Timer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Runnableprivate final javafx.util.Durationprivate longprivate final javafx.animation.Timeline -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TimerPrepares a (stopped) timer that lasts fordelayand whose action runs when timer ends.static TimercreatePeriodic(Duration interval, Runnable action) Prepares a (stopped) timer that lasts forintervaland that executes the given action periodically when the timer ends.static TimercreatePeriodic0(Duration interval, Runnable action) Prepares a (stopped) timer that lasts forintervaland that executes the given action periodically when the timer starts.voidrestart()Schedules the associated action to be executed after the associated delay.static TimerEquivalent tocreate(delay, action).restart().static TimerrunPeriodically(Duration interval, Runnable action) Equivalent tocreatePeriodic(interval, action).restart().static TimerrunPeriodically0(Duration interval, Runnable action) Equivalent tocreatePeriodic0(interval, action).restart().voidstop()If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all.
-
Field Details
-
actionTime
private final javafx.util.Duration actionTime -
timeline
private final javafx.animation.Timeline timeline -
action
-
seq
private long seq
-
-
Constructor Details
-
FxTimer
-
-
Method Details
-
create
-
runLater
-
createPeriodic
-
runPeriodically
-
createPeriodic0
-
runPeriodically0
-
restart
public void restart()Description copied from interface:TimerSchedules 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. -
stop
public void stop()Description copied from interface:TimerIf 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 byAnimation.stop():
In contrast, using theTimeline 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 printedFxTimer, the action is guaranteed not to be executed afterstop():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
-