NGP
Class Timer

java.lang.Object
  extended byNGP.Timer
All Implemented Interfaces:
ActionListener, EventListener
Direct Known Subclasses:
DefiniteTimer

public abstract class Timer
extends Object
implements ActionListener

An object that "activates" at a specified interval. This class can be used to help model both an "Animator" that might affect an entire program, or a "Behavior" that might affect only an individual object. The activate method will fire every time a certain number of milliseconds has passed. It is up to the subclass to override activate to determine what should take place.

This timer will not stop activating until the program ends or stop is called explicitly.

Author:
Matt Chotin (mhc)

Constructor Summary
Timer(int delay)
          Creates a Timer with a delay between activate calls
 
Method Summary
 void actionPerformed(ActionEvent e)
          Normal users need not deal with this method!
abstract  void activate()
          Called whenever the set time has expired.
 int getDelay()
          Return the number of milliseconds this Timer uses as a delay.
 void setDelay(int d)
          Set the number of milliseconds this Timer uses as a delay.
 void start()
          Start the timer, a timer is stopped by default.
 void stop()
          Stop the timer, a timer is stopped by default.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timer

public Timer(int delay)
Creates a Timer with a delay between activate calls

Parameters:
delay - milliseconds between activate calls
Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
Normal users need not deal with this method!

Called by the Swing Timer when the time has expired. It will then call activate which subclasses should override.

Specified by:
actionPerformed in interface ActionListener
Parameters:
e - the java.awt.event.ActionEvent that was sent, we do not deal with it

activate

public abstract void activate()
Called whenever the set time has expired. Subclasses should override to do something useful.


getDelay

public int getDelay()
Return the number of milliseconds this Timer uses as a delay.

Returns:
the number of milliseconds the Timer uses as a delay
See Also:
setDelay

setDelay

public void setDelay(int d)
Set the number of milliseconds this Timer uses as a delay.

Parameters:
d - the number of milliseconds the Timer should use as a delay
See Also:
getDelay

start

public void start()
Start the timer, a timer is stopped by default.

See Also:
stop

stop

public void stop()
Stop the timer, a timer is stopped by default.

See Also:
start