nl.justobjects.toolkit.sys
Class Timer

java.lang.Object
  |
  +--nl.justobjects.toolkit.sys.Timer
All Implemented Interfaces:
java.lang.Runnable

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

Interval timer thread with callback to client.

Purpose
It calls the tick method in the TimerCallback 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.

Implementation

Examples
To start up a timer with this class, create it with a callback and the number of milliseconds in the interval then call the start method:


	Timer timer = new Timer(this, 2000);	// 2 second interval
	timer.start();

 


$Source: /var/cvs/justobjects/toolkit/src/nl/justobjects/toolkit/sys/Timer.java,v $

Since:
$Date: 2003/01/06 00:23:49 $
Version:
$Revision: 1.5 $
Author:
$Author: just $ - Just van den Broecke - Just Objects ©
See Also:
TimerCallback

Field Summary
protected  TimerCallback callback
          The callback interface containing the tick method
protected  long interval
          The number of milliseconds in the interval
(package private) static int num
           
protected  java.lang.Thread timerThread
           
 
Constructor Summary
Timer()
           
Timer(long interval)
           
Timer(TimerCallback callback)
           
Timer(TimerCallback callback, long interval)
           
 
Method Summary
 TimerCallback getCallback()
          returns the callback interface
 long getInterval()
          returns the number of milliseconds in the interval
 void run()
           
 void setCallback(TimerCallback callback)
          changes the callback interface
 void setInterval(long newInterval)
          sets the number of milliseconds in the interval
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

num

static int num

timerThread

protected java.lang.Thread timerThread

interval

protected long interval
The number of milliseconds in the interval

callback

protected TimerCallback callback
The callback interface containing the tick method
Constructor Detail

Timer

public Timer()

Timer

public Timer(TimerCallback callback)

Timer

public Timer(long interval)

Timer

public Timer(TimerCallback callback,
             long interval)
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()

stop

public void stop()

run

public void run()
Specified by:
run in interface java.lang.Runnable


Copyright © 2000-2001 - Just Objects B.V.