| Modifier and Type | Method and Description |
|---|---|
static Timer |
create(java.time.Duration delay,
java.lang.Runnable action)
Prepares a (stopped) timer that lasts for
delay and whose action runs when timer ends. |
static Timer |
createPeriodic(java.time.Duration interval,
java.lang.Runnable action)
Prepares a (stopped) timer that lasts for
interval and that executes the given action periodically
when the timer ends. |
static Timer |
createPeriodic0(java.time.Duration interval,
java.lang.Runnable action)
Prepares a (stopped) timer that lasts for
interval and that executes the given action periodically
when the timer starts. |
void |
restart()
Schedules the associated action to be executed after the associated
delay.
|
static Timer |
runLater(java.time.Duration delay,
java.lang.Runnable action)
Equivalent to
create(delay, action).restart(). |
static Timer |
runPeriodically(java.time.Duration interval,
java.lang.Runnable action)
Equivalent to
createPeriodic(interval, action).restart(). |
static Timer |
runPeriodically0(java.time.Duration interval,
java.lang.Runnable action)
Equivalent to
createPeriodic0(interval, action).restart(). |
void |
stop()
If the associated action has been scheduled for execution but not yet
executed, this method prevents it from being executed at all.
|
public static Timer create(java.time.Duration delay, java.lang.Runnable action)
delay and whose action runs when timer ends.public static Timer runLater(java.time.Duration delay, java.lang.Runnable action)
create(delay, action).restart().public static Timer createPeriodic(java.time.Duration interval, java.lang.Runnable action)
interval and that executes the given action periodically
when the timer ends.public static Timer runPeriodically(java.time.Duration interval, java.lang.Runnable action)
createPeriodic(interval, action).restart().public static Timer createPeriodic0(java.time.Duration interval, java.lang.Runnable action)
interval and that executes the given action periodically
when the timer starts.public static Timer runPeriodically0(java.time.Duration interval, java.lang.Runnable action)
createPeriodic0(interval, action).restart().public void restart()
Timerpublic void stop()
TimerAnimation.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