All Packages Class Hierarchy This Package Previous Next Index
Class util.Timer
java.lang.Object
|
+----java.lang.Thread
|
+----util.Timer
- public class Timer
- extends Thread
The Timer class allows various timers to be created with multiple
events inside each timer allowed. Most of the time the user will just
need to use the createEvent routine and wait for the timer event to
be activated. All times are in milliseconds.
-
Timer(String, int)
- Create a new timer set with the given name and resolution.
-
createEvent(String, TimerListener, int, Object, int)
- This routine allows you to create a new event inside the named timer and is the
main access point to the timer routines.
-
createEvent(TimerListener, int, Object, int)
- If you already have a reference to a timer you can use this routine
to directly create the event.
-
getResolution(int)
- Get the current resolution of a timer.
-
getTimer(String)
- This method allows the user to access a given Timer.
-
removeEvent(TimerEvent)
- Remove an event by search ALL timers for the event.
-
removeEventFromTimer(TimerEvent)
- Remove an event from this timer.
-
rescheduleEvent(TimerEvent, int)
- Resechedule a timer event to occur later.
-
run()
-
-
setResolution(int)
- Change the resolution of a timer.
-
shutdown()
- This methods calls stopTimer on all the currently running timers.
-
stopTimer()
- Stop a timer from running.
-
toString()
-
-
toStringDetail()
- Get a detailed string of the timer, including all the events that
are waiting to be fired.
Timer
public Timer(String name,
int resolution)
- Create a new timer set with the given name and resolution.
- Parameters:
- name - The name of the timer
- resolution - The resolution of this time. How often we
should check to see if a timer event is ready
to be fired.
createEvent
public static synchronized TimerEvent createEvent(String timerName,
TimerListener listener,
int eventID,
Object callback,
int relTime)
- This routine allows you to create a new event inside the named timer and is the
main access point to the timer routines. If the timer specified doesn't exist
yet, it will automatically be created.
- Parameters:
- timerName - The name of the timer the event should be placed on
- listener - Who should be informed when the timer event is fired.
- eventID - The id of the event we are created. This id
is NOT used internally and is for external (listener)
use only. There CAN be multiple timer events with
the same eventID set to go off at different times.
- callback - A extra data item that will be passed to the listener
when the timer goes off. Can be null if you
don't have an extra data.
- relTime - How far in the future should this timer event be
fired?
- Returns:
- The timer event that has been created.
shutdown
public static synchronized void shutdown()
- This methods calls stopTimer on all the currently running timers.
getTimer
public static synchronized Timer getTimer(String timerName)
- This method allows the user to access a given Timer.
- Parameters:
- timerName - The timer the user wants to get
- Returns:
- The requested timer.
setResolution
public void setResolution(int res)
- Change the resolution of a timer.
getResolution
public long getResolution(int res)
- Get the current resolution of a timer.
createEvent
public synchronized TimerEvent createEvent(TimerListener listener,
int eventID,
Object callback,
int relTime)
- If you already have a reference to a timer you can use this routine
to directly create the event. The static createEvent calls this
method after first looking up the timer.
- Parameters:
- listener - Who should be informed when the timer event is fired.
- eventID - The id of the event we are created. This id
is NOT used internally and is for external (listener)
use only. There CAN be multiple timer events with
the same eventID set to go off at different times.
- callback - A extra data item that will be passed to the listener
when the timer goes off. Can be null if you
don't have an extra data.
- relTime - How far in the future should this timer event be
fired?
- Returns:
- The timer event that has been created.
toStringDetail
public synchronized String toStringDetail()
- Get a detailed string of the timer, including all the events that
are waiting to be fired.
toString
public String toString()
- Overrides:
- toString in class Thread
rescheduleEvent
public synchronized boolean rescheduleEvent(TimerEvent event,
int relTime)
- Resechedule a timer event to occur later.
- Parameters:
- event - The event we want to reschedule
- relTime - How many more milliseconds before the event should be fired.
- Returns:
- True if the event was rescheduled, false otherwise
removeEventFromTimer
public synchronized boolean removeEventFromTimer(TimerEvent event)
- Remove an event from this timer.
- Parameters:
- event - The event we want to remove
- Returns:
- True if the event was removed, false otherwise
removeEvent
public static synchronized boolean removeEvent(TimerEvent d)
- Remove an event by search ALL timers for the event.
- Parameters:
- event - The event we want to remove
- Returns:
- True if the event was removed, false otherwise
stopTimer
public synchronized void stopTimer()
- Stop a timer from running.
run
public void run()
- Overrides:
- run in class Thread
All Packages Class Hierarchy This Package Previous Next Index