|
Préférences
Moteurs de recherche
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.6.0
javax.swing
|
Field Summary | |
---|---|
protected EventListenerList |
listenerList
|
Constructor Summary | |
---|---|
Timer(int delay,
ActionListener listener)
Creates a Timer and initializes both the initial delay and
between-event delay to delay milliseconds. |
Method Summary | ||
---|---|---|
void |
addActionListener(ActionListener listener)
Adds an action listener to the Timer . |
|
protected void |
fireActionPerformed(ActionEvent e)
Notifies all listeners that have registered interest for notification on this event type. |
|
String |
getActionCommand()
Returns the string that will be delivered as the action command in ActionEvent s fired by this timer. |
|
ActionListener[] |
getActionListeners()
Returns an array of all the action listeners registered on this timer. |
|
int |
getDelay()
Returns the delay, in milliseconds, between firings of action events. |
|
int |
getInitialDelay()
Returns the Timer 's initial delay. |
|
|
getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListener s
upon this Timer . |
|
static boolean |
getLogTimers()
Returns true if logging is enabled. |
|
boolean |
isCoalesce()
Returns true if the Timer coalesces
multiple pending action events. |
|
boolean |
isRepeats()
Returns true (the default)
if the Timer will send
an action event
to its listeners multiple times. |
|
boolean |
isRunning()
Returns true if the Timer is running. |
|
void |
removeActionListener(ActionListener listener)
Removes the specified action listener from the Timer . |
|
void |
restart()
Restarts the Timer ,
canceling any pending firings and causing
it to fire with its initial delay. |
|
void |
setActionCommand(String command)
Sets the string that will be delivered as the action command in ActionEvent s fired by this timer. |
|
void |
setCoalesce(boolean flag)
Sets whether the Timer coalesces multiple pending
ActionEvent firings. |
|
void |
setDelay(int delay)
Sets the Timer 's between-event delay, the number of milliseconds
between successive action events. |
|
void |
setInitialDelay(int initialDelay)
Sets the Timer 's initial delay, the time
in milliseconds to wait after the timer is started
before firing the first event. |
|
static void |
setLogTimers(boolean flag)
Enables or disables the timer log. |
|
void |
setRepeats(boolean flag)
If flag is false ,
instructs the Timer to send only one
action event to its listeners. |
|
void |
start()
Starts the Timer ,
causing it to start sending action events
to its listeners. |
|
void |
stop()
Stops the Timer ,
causing it to stop sending action events
to its listeners. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected EventListenerList listenerList
Constructor Detail |
---|
public Timer(int delay, ActionListener listener)
Timer
and initializes both the initial delay and
between-event delay to delay
milliseconds. If delay
is less than or equal to zero, the timer fires as soon as it
is started. If listener
is not null
,
it's registered as an action listener on the timer.
delay
- milliseconds for the initial and between-event delaylistener
- an initial listener; can be null
addActionListener(java.awt.event.ActionListener)
,
setInitialDelay(int)
,
setRepeats(boolean)
Method Detail |
---|
public void addActionListener(ActionListener listener)
Timer
.
listener
- the listener to addTimer(int, java.awt.event.ActionListener)
public void removeActionListener(ActionListener listener)
Timer
.
listener
- the listener to removepublic ActionListener[] getActionListeners()
ActionListener
s or an empty
array if no action listeners are currently registeredaddActionListener(java.awt.event.ActionListener)
,
removeActionListener(java.awt.event.ActionListener)
protected void fireActionPerformed(ActionEvent e)
e
- the action event to fireEventListenerList
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListener
s
upon this Timer
.
FooListener
s
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.
listenerType
- the type of listeners requested;
this parameter should specify an interface
that descends from java.util.EventListener
FooListener
s
on this timer,
or an empty array if no such
listeners have been added
ClassCastException
- if listenerType
doesn't
specify a class or interface that implements
java.util.EventListener
getActionListeners()
,
addActionListener(java.awt.event.ActionListener)
,
removeActionListener(java.awt.event.ActionListener)
public static void setLogTimers(boolean flag)
System.out
whenever the timer goes off.
flag
- true
to enable logginggetLogTimers()
public static boolean getLogTimers()
true
if logging is enabled.
true
if logging is enabled; otherwise, falsesetLogTimers(boolean)
public void setDelay(int delay)
Timer
's between-event delay, the number of milliseconds
between successive action events. This does not affect the initial delay
property, which can be set by the setInitialDelay
method.
delay
- the delay in millisecondssetInitialDelay(int)
public int getDelay()
setDelay(int)
,
getInitialDelay()
public void setInitialDelay(int initialDelay)
Timer
's initial delay, the time
in milliseconds to wait after the timer is started
before firing the first event. Upon construction, this
is set to be the same as the between-event delay,
but then its value is independent and remains unaffected
by changes to the between-event delay.
initialDelay
- the initial delay, in millisecondssetDelay(int)
public int getInitialDelay()
Timer
's initial delay.
setInitialDelay(int)
,
setDelay(int)
public void setRepeats(boolean flag)
flag
is false
,
instructs the Timer
to send only one
action event to its listeners.
flag
- specify false
to make the timer
stop after sending its first action eventpublic boolean isRepeats()
true
(the default)
if the Timer
will send
an action event
to its listeners multiple times.
setRepeats(boolean)
public void setCoalesce(boolean flag)
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.
Timer
s
coalesce events by default.
flag
- specify false
to turn off coalescingpublic boolean isCoalesce()
true
if the Timer
coalesces
multiple pending action events.
setCoalesce(boolean)
public void setActionCommand(String command)
ActionEvent
s fired by this timer.
null
is an acceptable value.
command
- the action commandpublic String getActionCommand()
ActionEvent
s fired by this timer. May be
null
, which is also the default.
public void start()
Timer
,
causing it to start sending action events
to its listeners.
stop()
public boolean isRunning()
true
if the Timer
is running.
start()
public void stop()
Timer
,
causing it to stop sending action events
to its listeners.
start()
public void restart()
Timer
,
canceling any pending firings and causing
it to fire with its initial delay.