public class SimpleTimer extends Object implements Runnable, Timer
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
Constructor and Description |
---|
SimpleTimer(ActionListener listener,
String name,
int delay,
boolean daemon,
boolean fixedIntervals)
Construct a repeating timer.
|
Modifier and Type | Method and Description |
---|---|
boolean |
fireAction(ActionEvent e) |
int |
getDelay()
Get the timer delay.
|
int |
getInitialDelay()
Get the initial delay.
|
boolean |
isRunning()
Find out if the timer is running.
|
void |
run() |
void |
setActionListener(ActionListener listener)
Set the action listener.
|
void |
setInitialDelay(int initialDelay)
Set the initial timer delay.
|
void |
setRepeats(boolean repeats)
Specify whether the timer should repeatedly call the listener at the
specified intervals or run just once and finish.
|
void |
start()
Start the timer.
|
void |
stop()
Stop the timer.
|
public SimpleTimer(ActionListener listener, String name, int delay, boolean daemon, boolean fixedIntervals)
listener
- an action listener to be called at the scheduled time intervals.name
- name for the timer thread (see Thread.getName()
)..delay
- the timer delay in milliseconds.daemon
- true will run the timer thread as a daemon.fixedIntervals
- the value of true will deduct the time spent in
actionPerformed() from the sleep time. This makes the timer wake up precisely
at the scheduled intervals. The value of false will make the timer sleep
the full delay after the actionPerformed() method is completed to make sure
that the specified delay gets elapsed between each two subsequent actionPerformed() calls.public boolean isRunning()
public boolean fireAction(ActionEvent e)
public int getInitialDelay()
getInitialDelay
in interface Timer
public void setInitialDelay(int initialDelay)
setInitialDelay
in interface Timer
initialDelay
- the initial timer delay in milliseconds.public void setRepeats(boolean repeats)
setRepeats
in interface Timer
repeats
- true repeats, false runs just once.public void setActionListener(ActionListener listener)
listener
- the new action listener.public int getDelay()