All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.Timer

java.lang.Object
   |
   +----com.sun.java.swing.Timer

public class Timer
extends Object
implements Serializable
Object subclass that causes an action to occur at a predefined rate. For example, an animation object can use a JTimer as the trigger for drawing its next frame. Each Timer has a list of ActionListeners and a delay ( the time between actionPerfomed() calls). When delay milliseconds have passed, a JTimer sends the actionPerformed() message to its listeners. This cycle repeats until stop() is called, or halts immediately if the Jimer is configured to send its message just once.

Using a JTimer involves first creating it, then starting it using the start() method.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.


Variable Index

 o listenerList

Constructor Index

 o Timer(int, ActionListener)
Creates a JTimer that will notify its listeners every delay milliseconds.

Method Index

 o addActionListener(ActionListener)
Adds an actionListener to the Timer
 o fireActionPerformed(ActionEvent)
 o getDelay()
Returns the Timer's delay.
 o getInitialDelay()
Returns the Timer's initial delay.
 o getLogTimers()
 o isCoalesce()
Returns true if the Timer coalesces multiple pending performCommand() messages.
 o isRepeats()
Returns true if the Timer will send a actionPerformed() message to its listeners multiple times.
 o isRunning()
Returns true if the Timer is running.
 o removeActionListener(ActionListener)
Removes an ActionListener from the Timer.
 o restart()
Restarts a Timer, canceling any pending firings, and causing it to fire with its initial dely.
 o setCoalesce(boolean)
Sets whether the Timer coalesces multiple pending ActionEvent firings.
 o setDelay(int)
Sets the Timer's delay, the number of milliseconds between successive actionPerfomed() messages to its listeners
 o setInitialDelay(int)
Sets the Timer's initial delay.
 o setLogTimers(boolean)
 o setRepeats(boolean)
If flag is false, instructs the Timer to send actionPerformed() to its listeners only once, and then stop.
 o start()
Starts the Timer, causing it to send actionPerformed() messages to its listeners.
 o stop()
Stops a Timer, causing it to stop sending actionPerformed() messages to its Target.

Variables

 o listenerList
 protected EventListenerList listenerList

Constructors

 o Timer
 public Timer(int delay,
              ActionListener listener)
Creates a JTimer that will notify its listeners every delay milliseconds.

Parameters:
delay - The number of milliseconds between listener notification
listener - An initial listener
See Also:
setInitialDelay, setRepeats

Methods

 o addActionListener
 public void addActionListener(ActionListener listener)
Adds an actionListener to the Timer

 o removeActionListener
 public void removeActionListener(ActionListener listener)
Removes an ActionListener from the Timer.

 o fireActionPerformed
 protected void fireActionPerformed(ActionEvent e)
 o setLogTimers
 public static void setLogTimers(boolean flag)
 o getLogTimers
 public static boolean getLogTimers()
 o setDelay
 public void setDelay(int delay)
Sets the Timer's delay, the number of milliseconds between successive actionPerfomed() messages to its listeners

See Also:
setInitialDelay
 o getDelay
 public int getDelay()
Returns the Timer's delay.

See Also:
setDelay
 o setInitialDelay
 public void setInitialDelay(int initialDelay)
Sets the Timer's initial delay. This will be used for the first "ringing" of the Timer only. Subsequent ringings will be spaced using the delay property.

See Also:
setDelay
 o getInitialDelay
 public int getInitialDelay()
Returns the Timer's initial delay.

See Also:
setDelay
 o setRepeats
 public void setRepeats(boolean flag)
If flag is false, instructs the Timer to send actionPerformed() to its listeners only once, and then stop.

 o isRepeats
 public boolean isRepeats()
Returns true if the Timer will send a actionPerformed() message to its listeners multiple times.

See Also:
setRepeats
 o setCoalesce
 public void setCoalesce(boolean flag)
Sets whether the Timer coalesces multiple pending ActionEvent firings. A busy application may not be able to keep up with a Timer's message generation, causing multiple actionPerformed() message sends to be queued. When processed, the application sends these messages one after the other, causing the Timer's listeners to receive a sequence of actionPerformed() messages with no delay between them. Coalescing avoids this situation by reducing multiple pending messages to a single message send. Timers coalesce their message sends by default.

 o isCoalesce
 public boolean isCoalesce()
Returns true if the Timer coalesces multiple pending performCommand() messages.

See Also:
setCoalesce
 o start
 public void start()
Starts the Timer, causing it to send actionPerformed() messages to its listeners.

See Also:
stop
 o isRunning
 public boolean isRunning()
Returns true if the Timer is running.

See Also:
start
 o stop
 public void stop()
Stops a Timer, causing it to stop sending actionPerformed() messages to its Target.

See Also:
start
 o restart
 public void restart()
Restarts a Timer, canceling any pending firings, and causing it to fire with its initial dely.


All Packages  Class Hierarchy  This Package  Previous  Next  Index