javax.swing
Class Timer
- Serializable
Fires one or more action events after the specified delay. This is
a specialised version of java.util.Timer
just for
firing ActionEvent
s. All Timers share one (daemon)
Thread (or java.util.Timer). All events are fired from the event
queue.
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
Timer
public Timer(int d,
ActionListener listener)
Creates a new Timer object.
d
- the default value for both initial and between event delay, in
milliseconds.listener
- the first action listener, can be null
.
extends EventListener> T[] getListeners
public extends EventListener> T[] getListeners(Class listenerType)
Get the event listeners of the given type that are listening for the
events, fired by this timer.
listenerType
- the listener type (for example, ActionListener.class)
- the array of event listeners that are listening for the events,
fired by this timer
fireActionPerformed
protected void fireActionPerformed(ActionEvent event)
Fire the given action event to the action listeners.
event
- the event to fire
getActionListeners
public ActionListener[] getActionListeners()
Get the array of action listeners.
- the array of action listeners that are listening for the events,
fired by this timer
getDelay
public int getDelay()
Get the delay between firing the subsequent events.
- The delay between subsequent events, in milliseconds
getInitialDelay
public int getInitialDelay()
Get the intial delay before firing the first event since calling
the
start()
method. If the initial delay has not been
set, returns the same value as
getDelay()
.
- the initial delay before firing the first action event.
getLogTimers
public static boolean getLogTimers()
Return the logging state.
true
if the timer is printing a message to
System.out
when firing each action event
isCoalesce
public boolean isCoalesce()
Checks if the Timer coalesces multiple pending event firings.
If the coalescing is enabled, the multiple events that have not been
fired on time are replaced by the single event. The events may not
be fired on time if the application is busy.
true
if the coalescing is enabled,
false
otherwise
isRepeats
public boolean isRepeats()
Check is this timer fires repetetive events.
true
if the timer fires repetetive events,
false
if it fires
only one event after the initial delay
isRunning
public boolean isRunning()
Get the timer state.
true
if the timer has been started and is firing
the action events as scheduled. false
if the timer is inactive.
restart
public void restart()
Cancel all pending tasks and fire the first event after the initial
delay.
setCoalesce
public void setCoalesce(boolean c)
Sets whether the Timer coalesces multiple pending event firings.
If the coalescing is enabled, the multiple events that have not been
fired on time are replaced by the single event. The events may not
be fired on time if the application is busy.
c
- true
(default) to enable the event coalescing,
false
otherwise
setDelay
public void setDelay(int d)
Set the delay between firing the subsequent events.
This parameter does not change the value of the initial delay before
firing the first event.
d
- The time gap between the subsequent events, in milliseconds
setInitialDelay
public void setInitialDelay(int i)
Set the intial delay before firing the first event since calling
the
start()
method. If the initial delay has not been
set, it is assumed having the same value as the delay between the
subsequent events.
i
- the initial delay, in milliseconds
setLogTimers
public static void setLogTimers(boolean lt)
Set the timer logging state. If it is set to
true
, the
timer prints a message to
System.out
when firing each
action event.
lt
- true
if logging is enabled, false
(default value) otherwise
setRepeats
public void setRepeats(boolean r)
Enable firing the repetetive events.
r
- true
(default value) to fire repetetive events.
false
to fire
only one event after the initial delay
start
public void start()
Start firing the action events.
stop
public void stop()
Stop firing the action events.
Timer.java --
Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.