javax.swing
Class Timer

java.lang.Object
  |
  +--javax.swing.Timer
All Implemented Interfaces:
Serializable

public class Timer
extends Object
implements Serializable

Unsafe:

See Also:
Serialized Form

Field Summary
(package private)  boolean coalesce
           
(package private)  int delay
           
(package private)  Runnable doPostEvent
           
(package private)  long expirationTime
           
(package private)  int initialDelay
           
protected  EventListenerList listenerList
           
private static boolean logTimers
           
(package private)  Timer nextTimer
           
private  boolean notify
           
(package private)  boolean repeats
           
(package private)  boolean running
           
 
Constructor Summary
Timer(int delay, ActionListener listener)
          Suppressed: Creates a Timer that will notify its listeners every delay milliseconds.
 
Method Summary
 void addActionListener(ActionListener listener)
          Suppressed: Adds an action listener to the Timer.
(package private)  void cancelEvent()
          Resets the internal state to indicate this Timer shouldn't notify any of its listeners.
protected  void fireActionPerformed(ActionEvent e)
          Notifies all listeners that have registered interest for notification on this event type.
 ActionListener[] getActionListeners()
          Suppressed: Returns an array of all the action listeners registered on this timer.
 int getDelay()
          Suppressed: Returns the delay, in milliseconds, between firings of action events.
 int getInitialDelay()
          Suppressed: Returns the Timer's initial delay.
 EventListener[] getListeners(Class listenerType)
          Suppressed: Returns an array of all the objects currently registered as FooListeners upon this Timer.
static boolean getLogTimers()
          Suppressed: Returns true if logging is enabled.
 boolean isCoalesce()
          Suppressed: Returns true if the Timer coalesces multiple pending action events.
 boolean isRepeats()
          Suppressed: Returns true (the default) if the Timer will send an action event to its listeners multiple times.
 boolean isRunning()
          Suppressed: Returns true if the Timer is running.
(package private)  void post()
           
 void removeActionListener(ActionListener listener)
          Suppressed: Removes the specified action listener from the Timer.
 void restart()
          Suppressed: Restarts the Timer, canceling any pending firings and causing it to fire with its initial delay.
 void setCoalesce(boolean flag)
          Suppressed: Sets whether the Timer coalesces multiple pending ActionEvent firings.
 void setDelay(int delay)
          Suppressed: Sets the Timer's delay, the number of milliseconds between successive action events.
 void setInitialDelay(int initialDelay)
          Suppressed: Sets the Timer's initial delay, which by default is the same as the between-event delay.
static void setLogTimers(boolean flag)
          Suppressed: Enables or disables the timer log.
 void setRepeats(boolean flag)
          Suppressed: If flag is false, instructs the Timer to send only one action event to its listeners.
 void start()
          Suppressed: Starts the Timer, causing it to start sending action events to its listeners.
 void stop()
          Suppressed: Stops the Timer, causing it to stop sending action events to its listeners.
(package private)  TimerQueue timerQueue()
          Returns the timer queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerList

protected EventListenerList listenerList

notify

private boolean notify

initialDelay

int initialDelay

delay

int delay

repeats

boolean repeats

coalesce

boolean coalesce

doPostEvent

Runnable doPostEvent

logTimers

private static boolean logTimers

expirationTime

long expirationTime

nextTimer

Timer nextTimer

running

boolean running
Constructor Detail

Timer

public Timer(int delay,
             ActionListener listener)
Suppressed: Creates a Timer that will notify its listeners every delay milliseconds. If delay is less than or equal to zero the timer will fire as soon as it is started. If listener is not null, it's registered as an action listener on the timer.

Parameters:
delay - the number of milliseconds between action events
listener - an initial listener; can be null
See Also:
addActionListener(java.awt.event.ActionListener), setInitialDelay(int), setRepeats(boolean)
Method Detail

addActionListener

public void addActionListener(ActionListener listener)
Suppressed: Adds an action listener to the Timer.

Parameters:
listener - the listener to add
See Also:
Timer(int, java.awt.event.ActionListener)

removeActionListener

public void removeActionListener(ActionListener listener)
Suppressed: Removes the specified action listener from the Timer.

Parameters:
listener - the listener to remove

getActionListeners

public ActionListener[] getActionListeners()
Suppressed: Returns an array of all the action listeners registered on this timer.

Returns:
all of the timer's ActionListeners or an empty array if no action listeners are currently registered
Since:
1.4
See Also:
addActionListener(java.awt.event.ActionListener), removeActionListener(java.awt.event.ActionListener)

fireActionPerformed

protected void fireActionPerformed(ActionEvent e)
Notifies all listeners that have registered interest for notification on this event type.

Parameters:
e - the action event to fire
See Also:
EventListenerList

getListeners

public EventListener[] getListeners(Class listenerType)
Suppressed: Returns an array of all the objects currently registered as FooListeners upon this Timer. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a Timer instance t for its action listeners with the following code:

ActionListener[] als = (ActionListener[])(t.getListeners(ActionListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this timer, or an empty array if no such listeners have been added
Since:
1.3
See Also:
getActionListeners(), addActionListener(java.awt.event.ActionListener), removeActionListener(java.awt.event.ActionListener)

timerQueue

TimerQueue timerQueue()
Returns the timer queue.


setLogTimers

public static void setLogTimers(boolean flag)
Suppressed: Enables or disables the timer log. When enabled, a message is posted to System.out whenever the timer goes off.

Parameters:
flag - true to enable logging
See Also:
getLogTimers()

getLogTimers

public static boolean getLogTimers()
Suppressed: Returns true if logging is enabled.

Returns:
true if logging is enabled; otherwise, false
See Also:
setLogTimers(boolean)

setDelay

public void setDelay(int delay)
Suppressed: Sets the Timer's delay, the number of milliseconds between successive action events.

Parameters:
delay - the delay in milliseconds
See Also:
setInitialDelay(int)

getDelay

public int getDelay()
Suppressed: Returns the delay, in milliseconds, between firings of action events.

See Also:
setDelay(int), getInitialDelay()

setInitialDelay

public void setInitialDelay(int initialDelay)
Suppressed: Sets the Timer's initial delay, which by default is the same as the between-event delay. This is used only for the first action event. Subsequent action events are spaced using the delay property.

Parameters:
initialDelay - the delay, in milliseconds, between the invocation of the start method and the first action event fired by this timer
See Also:
setDelay(int)

getInitialDelay

public int getInitialDelay()
Suppressed: Returns the Timer's initial delay.

See Also:
setInitialDelay(int), setDelay(int)

setRepeats

public void setRepeats(boolean flag)
Suppressed: If flag is false, instructs the Timer to send only one action event to its listeners.

Parameters:
flag - specify false to make the timer stop after sending its first action event

isRepeats

public boolean isRepeats()
Suppressed: Returns true (the default) if the Timer will send an action event to its listeners multiple times.

See Also:
setRepeats(boolean)

setCoalesce

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

Parameters:
flag - specify false to turn off coalescing

isCoalesce

public boolean isCoalesce()
Suppressed: Returns true if the Timer coalesces multiple pending action events.

See Also:
setCoalesce(boolean)

start

public void start()
Suppressed: Starts the Timer, causing it to start sending action events to its listeners.

See Also:
stop()

isRunning

public boolean isRunning()
Suppressed: Returns true if the Timer is running.

See Also:
start()

stop

public void stop()
Suppressed: Stops the Timer, causing it to stop sending action events to its listeners.

See Also:
start()

restart

public void restart()
Suppressed: Restarts the Timer, canceling any pending firings and causing it to fire with its initial delay.


cancelEvent

void cancelEvent()
Resets the internal state to indicate this Timer shouldn't notify any of its listeners. This does not stop a repeatable Timer from firing again, use stop for that.


post

void post()


comments?