|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nl.kun.Engine3D.TickTimer
This class implements an interval timer. It calls the tick method in the callback interface after a fixed number of milliseconds (indicated by the interval variable). It measures the amount of time spent in the tick method and adjusts for it. To start up a timer with this class, create it with a callback and the number of milliseconds in the interval and then call the start method:
Timer timer = new Timer(this, 2000); // 2 second interval timer.start();
Field Summary | |
protected TimerCallback |
callback
The callback interface containing the tick method |
protected long |
interval
The number of milliseconds in the interval |
protected boolean |
threadSuspended
Flag that indicates if the thread is suspended |
java.lang.Thread |
timerThread
The timer thread. |
Constructor Summary | |
TickTimer()
Empty constructor |
|
TickTimer(long interval)
Constructor with only an interval declared. |
|
TickTimer(TimerCallback callback)
Constructor where a callback is defined |
|
TickTimer(TimerCallback callback,
long interval)
Complete constructor with callback and interval |
Method Summary | |
TimerCallback |
getCallback()
returns the callback interface |
long |
getInterval()
returns the number of milliseconds in the interval |
void |
pauze()
pauzes the timer |
void |
resume()
resumes the paused timer |
void |
run()
threads procedure. |
void |
setCallback(TimerCallback callback)
changes the callback interface |
void |
setInterval(long newInterval)
sets the number of milliseconds in the interval |
void |
start()
starts the timer |
void |
stop()
stops the timer |
void |
switchActive()
switches the timer between paused and resumed |
Methods inherited from class java.lang.Object |
|
Field Detail |
public java.lang.Thread timerThread
protected long interval
protected TimerCallback callback
protected boolean threadSuspended
Constructor Detail |
public TickTimer()
public TickTimer(TimerCallback callback)
callback
- The class that implements the TimerCallback interfacepublic TickTimer(long interval)
interval
- The interval of the timer in millisecondspublic TickTimer(TimerCallback callback, long interval)
interval
- The interval of the timer in millisecondscallback
- The class that implements the TimerCallback interfaceMethod Detail |
public long getInterval()
public void setInterval(long newInterval)
newInterval
- the new number of millisecondspublic TimerCallback getCallback()
public void setCallback(TimerCallback callback)
callback
- the new callbackpublic void start()
public void pauze()
public void resume()
public void switchActive()
public void stop()
public void run()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |