FileDocCategorySizeDatePackage
Timer.javaAPI DocExample1224Sat Apr 23 22:35:42 BST 2005magicbeans

Timer

public class Timer extends Object implements Runnable

Fields Summary
long
delay
Thread
thread
boolean
stopped
List
listeners
Constructors Summary
public Timer()


	   
		start();
	
Methods Summary
public voidaddTimerListener(TimerListener listener)

		listeners.add( listener );
	
voidfireEvent()

		for ( TimerListener listener : listeners )
			listener.timerFired( new TimerEvent(this) );
	
public longgetDelay()

 return this.delay; 
public booleanisRunning()

 return !stopped; 
public voidremoveTimerListener(TimerListener listener)

		listeners.remove( listener );
	
public voidrun()

		while( !stopped )
		{
			fireEvent();
			try {
				Thread.sleep( delay );
			} catch ( InterruptedException e ) {
				return; // die
			}
		}
	
public voidsetDelay(long delay)

 this.delay = delay; 
public voidsetRunning(boolean b)

 
		if ( b ) 
			start();
		else
			stop();
	
public synchronized voidstart()

		if ( stopped )
		{
			stopped = false;
			thread = new Thread(this);
			thread.start();
		}
	
public synchronized voidstop()

 
		if ( !stopped )
		{
			stopped = true;
			if ( thread != null )
				thread.interrupt();
		}