nl.kun.Engine3D
Class TickTimer

java.lang.Object
  |
  +--nl.kun.Engine3D.TickTimer

public class TickTimer
extends java.lang.Object
implements java.lang.Runnable

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
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timerThread

public java.lang.Thread timerThread
The timer thread. Can be monitored to see if the timer is active

interval

protected long interval
The number of milliseconds in the interval

callback

protected TimerCallback callback
The callback interface containing the tick method

threadSuspended

protected boolean threadSuspended
Flag that indicates if the thread is suspended
Constructor Detail

TickTimer

public TickTimer()
Empty constructor

TickTimer

public TickTimer(TimerCallback callback)
Constructor where a callback is defined
Parameters:
callback - The class that implements the TimerCallback interface

TickTimer

public TickTimer(long interval)
Constructor with only an interval declared.
Parameters:
interval - The interval of the timer in milliseconds

TickTimer

public TickTimer(TimerCallback callback,
                 long interval)
Complete constructor with callback and interval
Parameters:
interval - The interval of the timer in milliseconds
callback - The class that implements the TimerCallback interface
Method Detail

getInterval

public long getInterval()
returns the number of milliseconds in the interval

setInterval

public void setInterval(long newInterval)
sets the number of milliseconds in the interval
Parameters:
newInterval - the new number of milliseconds

getCallback

public TimerCallback getCallback()
returns the callback interface

setCallback

public void setCallback(TimerCallback callback)
changes the callback interface
Parameters:
callback - the new callback

start

public void start()
starts the timer

pauze

public void pauze()
pauzes the timer

resume

public void resume()
resumes the paused timer

switchActive

public void switchActive()
switches the timer between paused and resumed

stop

public void stop()
stops the timer

run

public void run()
threads procedure. Never called by the user
Specified by:
run in interface java.lang.Runnable