Package doodlepad
Class Timer
java.lang.Object
doodlepad.Timer
A class that implements a stand-alone, non-graphical Timer object.
Provides for multiple Timers in a single program.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface used by methods that assign timer event handlers given a method reference as a parameter. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add object to the list of items that are notified on Timer start action.void
Add object to the list of items that are notified on Timer stop action.void
Add object to the list of items that are notified on Timer's tick action.protected void
finalize()
Stop internal Timer when garbage collected.final double
Return the current rate at which the timer ticksboolean
Determine if the timer is runningvoid
onStart
(long when) A method that can be overridden to handle the timer`s start event.void
onStop
(long when) A method that can be overridden to handle the timer`s stop event.void
onTick
(long when) A method that can be overridden to handle the timer`s tick event.void
Remove object from Timer's start action listener list.void
Remove object from Timer's start action listener list.void
Remove object from Timer's tick action listener list.void
setStartHandler
(Timer.TimerEventHandler handler) Assign an onStart event handler using a method reference.void
setStopHandler
(Timer.TimerEventHandler handler) Assign an onStop event handler using a method reference.void
setTickHandler
(Timer.TimerEventHandler handler) Assign an onTick event handler using a method reference.final void
setTickRate
(double tps) Set the rate at which to fire onTick eventsvoid
Start the timer firing onTick events.void
Stop timervoid
Toggle the state of the timer.
-
Constructor Details
-
Timer
public Timer()Nullary constructor setting default tick rate -
Timer
public Timer(double tps) Timer constructor with initial tick rate parameter- Parameters:
tps
- Ticks per second
-
-
Method Details
-
setTickRate
public final void setTickRate(double tps) Set the rate at which to fire onTick events- Parameters:
tps
- Ticks per second
-
getTickRate
public final double getTickRate()Return the current rate at which the timer ticks- Returns:
- A double indicating ticks per second.
-
startTimer
public void startTimer()Start the timer firing onTick events. -
stopTimer
public void stopTimer()Stop timer -
toggleTimer
public void toggleTimer()Toggle the state of the timer. Started/Stopped. -
isRunning
public boolean isRunning()Determine if the timer is running- Returns:
- True or false indicating if the timer is running.
-
setStartHandler
Assign an onStart event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setTickHandler
Assign an onTick event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setStopHandler
Assign an onStop event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
onTick
public void onTick(long when) A method that can be overridden to handle the timer`s tick event. The timer tick rate is set with the setTickRate() method. The timer is started by invoking the startTimer() method. The timer is stopped by invoking the stopTimer() method.- Parameters:
when
- The difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.
-
onStart
public void onStart(long when) A method that can be overridden to handle the timer`s start event. The timer is started by invoking the startTimer() method.- Parameters:
when
- The difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.
-
onStop
public void onStop(long when) A method that can be overridden to handle the timer`s stop event. The timer is stopped by invoking the stopTimer() method.- Parameters:
when
- The difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.
-
addStartListener
Add object to the list of items that are notified on Timer start action.- Parameters:
o
- An object that implements the TimerTickListener interface.
-
removeStartListener
Remove object from Timer's start action listener list.- Parameters:
o
- The TimerEventListener object to be removed.
-
addTickListener
Add object to the list of items that are notified on Timer's tick action.- Parameters:
o
- An object that implements the ActionListener interface.
-
removeTickListener
Remove object from Timer's tick action listener list.- Parameters:
o
- The ActionListener object to be removed.
-
addStopListener
Add object to the list of items that are notified on Timer stop action.- Parameters:
o
- An object that implements the TimerEventListener interface.
-
removeStopListener
Remove object from Timer's start action listener list.- Parameters:
o
- The TimerTickListener object to be removed.
-
finalize
Stop internal Timer when garbage collected.
-