public class Timer
extends java.lang.Object
implements java.io.Serializable
Timer object causes an action to occur at a predefined
rate. For example, an animation object can use a Timer 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 Timer sends the actionPerformed()
message to its listeners. This cycle repeats until stop() is
called, or halts immediately if the Timer is configured to send its
message just once.
Using a Timer involves first creating it, then starting it using the start() method.
The API of this class is designed based on
com.sun.java.swing.Timer in swing 0.5.1,
but the implementation of this class is original.
| 修飾子とタイプ | フィールドと説明 |
|---|---|
protected java.awt.event.ActionListener |
actionListener
The action listeners.
|
protected static java.lang.String |
actionListenerK
Internal constant for serialization
|
protected int |
delay
The delay in milliseconds.
|
protected int |
initialDelay
The initial delay in milliseconds.
|
protected boolean |
isRunning
True if the timer is running.
|
protected boolean |
repeats
True if the timer is fired multiple times.
|
protected static jp.kyasu.awt.TimerQueue |
TQueue
The timer queue that ringings timer objects.
|
protected static jp.kyasu.awt.TimerThread |
TThread
The timer thread that takes timers off the TimerQueue and fires them.
|
protected long |
wakeUpTime
The wake up time of the timer.
|
| コンストラクタと説明 |
|---|
Timer(int delay,
java.awt.event.ActionListener listener)
Constructs a timer that will notify its listeners every delay
milliseconds.
|
Timer(int initialDelay,
int delay,
java.awt.event.ActionListener listener)
Constructs a timer that will notify its listeners every delay
milliseconds.
|
| 修飾子とタイプ | メソッドと説明 |
|---|---|
void |
addActionListener(java.awt.event.ActionListener l)
Adds an actionListener to the timer.
|
int |
getDelay()
Returns the timer's delay.
|
int |
getInitialDelay()
Returns the timer's initial delay.
|
boolean |
isRunning()
Returns
true if the timer is running. |
protected void |
notifyActionListeners() |
void |
removeActionListener(java.awt.event.ActionListener l)
Removes an ActionListener from the timer.
|
boolean |
repeats()
Returns
true if the timer will send a
actionPerformed() message to its listeners multiple
times. |
void |
restart()
Restarts the timer, cancelling any pending firings, and causing
it to fire with its initial dely.
|
void |
setDelay(int delay)
Sets the timer's delay, the number of milliseconds between
successive
actionPerfomed() messages to its listeners. |
void |
setInitialDelay(int initialDelay)
Sets the timer's initial delay.
|
void |
setRepeats(boolean flag)
If the specified flag is
false, instructs the timer
to send actionPerformed() to its listeners only once,
and then stop. |
void |
start()
Starts the timer, causing it to send
actionPerformed()
messages to its listeners. |
protected static void |
startTimerThread()
Starts the timer thread.
|
void |
stop()
Stops the timer, causing it to stop sending
actionPerformed() messages to its listeners. |
protected static void |
stopTimerThread()
Stops the timer thread.
|
protected int initialDelay
protected int delay
protected transient java.awt.event.ActionListener actionListener
protected boolean repeats
protected boolean isRunning
protected long wakeUpTime
protected static final jp.kyasu.awt.TimerQueue TQueue
protected static jp.kyasu.awt.TimerThread TThread
protected static final java.lang.String actionListenerK
public Timer(int delay,
java.awt.event.ActionListener listener)
delay - The number of milliseconds between listener
notification.listener - An initial listener.public Timer(int initialDelay,
int delay,
java.awt.event.ActionListener listener)
initialDelay - the initial delay.delay - The number of milliseconds between listener
notification.listener - An initial listener.protected static void startTimerThread()
protected static void stopTimerThread()
public void addActionListener(java.awt.event.ActionListener l)
public void removeActionListener(java.awt.event.ActionListener l)
public int getInitialDelay()
public void setInitialDelay(int initialDelay)
public int getDelay()
public void setDelay(int delay)
actionPerfomed() messages to its listeners.public boolean repeats()
true if the timer will send a
actionPerformed() message to its listeners multiple
times.public void setRepeats(boolean flag)
false, instructs the timer
to send actionPerformed() to its listeners only once,
and then stop.public boolean isRunning()
true if the timer is running.public void start()
actionPerformed()
messages to its listeners.public void stop()
actionPerformed() messages to its listeners.public void restart()
protected void notifyActionListeners()