Package com.nt.udc.util
Class UDCSimpleTimer
java.lang.Object
com.nt.udc.util.UDCSimpleTimer
This is a simple timer that can be used to periodically cause a specific
action to be performed on an object listening to the timer.
-
Constructor Summary
ConstructorsConstructorDescriptionUDCSimpleTimer
(int delay, ActionListener listener) Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions.UDCSimpleTimer
(int delay, ActionListener listener, int repeat) Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions.UDCSimpleTimer
(long delay, ActionListener listener) UDCSimpleTimer
(long delay, ActionListener listener, int repeat) -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
Indicates whether the timer is runningvoid
restart()
Reset the timer.void
restart
(int delay) Reset the timer.void
setRepeats
(boolean repeat) Ifrepeat
isfalse
, the timer to send actionPerformed() to its listener only once, and then stop.void
skipToEvent
(boolean skip) Causes or prevents the current timer iteration to/from proceeding to the next event.void
start()
Start the timervoid
stop()
Stop the timer.
-
Constructor Details
-
UDCSimpleTimer
Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions. Once thestart()
method has been called, the timer will continue to cycle until thestop()
method is called.- Parameters:
delay
- The number of milliseconds this timer will sleep between calls to theActionListener
.listener
- AnActionListener
object which will have itsactionPerformed()
method called when the timer's 'delay' time has expired.
-
UDCSimpleTimer
-
UDCSimpleTimer
Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions. Once thestart()
method has been called, the timer will cycle as many times as indicated by the value ofrepeat
. A value of zero (0) indicates the timer should run until thestop()
method is called.- Parameters:
delay
- The number of milliseconds this timer will sleep between calls to theActionListener
.listener
- AnActionListener
object which will have itsactionPerformed()
method called the timer's 'delay' time has expired.repeat
- Number of times this timer will run.
-
UDCSimpleTimer
-
-
Method Details
-
isRunning
public boolean isRunning()Indicates whether the timer is running -
setRepeats
public void setRepeats(boolean repeat) Ifrepeat
isfalse
, the timer to send actionPerformed() to its listener only once, and then stop. This method exists to mimic the javax.swing.Timer class. However, a finer granularity can be achieved by setting the repeat value via the constructor. -
start
public void start()Start the timer -
restart
public void restart()Reset the timer. If the timer is running, the current cycle will be interrupted, the designated action on the ActionListener will not be performed and the next cycle will begin, provided the 'repeat count' has not been exceeded.
If the timer is not running, it will be started; -
skipToEvent
public void skipToEvent(boolean skip) Causes or prevents the current timer iteration to/from proceeding to the next event. If set to true, then the current iteration will proceed to the next event. If the timer is sleeping, it will wake up. If the timer is not sleeping, then it will skip the NEXT timer period, and generate the next event immediately. If set to false, then the next timer iteration will proceed normally, waiting according to the specified delay. This method will most likely use the "true" setting. However, "false" may be used in the implemented "actionListener" so that its "actionPerformed()" method will not be called immediately.- Parameters:
skip
- true, to skip the NEXT timer, or interrupt the current timer. false, to proceed as normal
-
restart
public void restart(int delay) Reset the timer. If the timer is running, the current cycle will be interrupted, the designated action on the ActionListener will not be performed and the next cycle will begin, provided the 'repeat count' has not been exceeded.
If the timer is not running, it will be started;- Parameters:
delay
- Resets the delay of the timer to the given value
-
stop
public void stop()Stop the timer. The current cycle will be interrupted and the designated action on the ActionListener will not be performed. -
isHealthy
public boolean isHealthy()
-