public class SharableTimer extends Timer
To start this timer, the starting context must call one of the following methods:
and give this Timer the delay, the coalesce state and all relevantActionListeners
listening to this Timer.
Before beginning to send ActionEvents to the Listeners,
this Timer will add the specified ActionListeners.
A call to stop()
will remove these added ActionListeners.
Of course, all other ActionListeners which were added by the
inherited method Timer.addActionListener(ActionListener)
wont be removed.
Further more this Timer fires a ChangeEvent to all added ChangeListeners whenever it has been started or stopped.
As an example you can check up both Joggle
and
TimerControlPanel
.
Modifier and Type | Field and Description |
---|---|
protected EventListenerList |
changeListenerList |
listenerList
Constructor and Description |
---|
SharableTimer()
Creates a new SharableTimer with a delay of 0 and no ActionListener.
|
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(ChangeListener l)
Adds a listener to the list that is notified each time this Timer
will be started or stopped.
|
protected void |
fireStateChanged()
Sends a ChangeEvent, whose source is this Timer, to each
ChangeListener which was added to this Timer.
|
void |
removeChangeListener(ChangeListener l)
Removes a ChangeListener from this Timer.
|
void |
start()
Does nothing - please use one of the other start methods to
start this Timer.
|
void |
start(int delay,
ActionListener[] listenerToAdd,
boolean coalesce)
Adds all
listenerToAdd , starts this Timer and calls
fireStateChanged() . |
void |
start(int delay,
ActionListener listenerToAdd,
boolean coalesce)
Similar to
start(int, ActionListener[], boolean) , but expecting
only one ActionListener to add. |
void |
stop()
Stops this Timer, removes the added ActionListeners recently given
to one of the start-methods and calls
fireStateChanged() . |
addActionListener, fireActionPerformed, getActionCommand, getActionListeners, getDelay, getInitialDelay, getListeners, getLogTimers, isCoalesce, isRepeats, isRunning, removeActionListener, restart, setActionCommand, setCoalesce, setDelay, setInitialDelay, setLogTimers, setRepeats
protected EventListenerList changeListenerList
public SharableTimer()
public void addChangeListener(ChangeListener l)
l
- the ChangeListener to addprotected void fireStateChanged()
addChangeListener(ChangeListener l)
public void removeChangeListener(ChangeListener l)
l
- the listener to remove.public void start()
start
in class Timer
start(int, ActionListener[], boolean)
,
start(int, ActionListener, boolean)
public void start(int delay, ActionListener[] listenerToAdd, boolean coalesce)
listenerToAdd
, starts this Timer and calls
fireStateChanged()
.
If this timer is already running it will previously be stopped
and starts running with the new parameters - in other words:
this Timer will be restarted.delay
- the timer delay.listenerToAdd
- all ActionListeners to add before starting this timer.coalesce
- the coalesce state this Timer should work with.Timer.setDelay(int)
,
Timer.setCoalesce(boolean)
,
Timer.addActionListener(ActionListener)
public void start(int delay, ActionListener listenerToAdd, boolean coalesce)
start(int, ActionListener[], boolean)
, but expecting
only one ActionListener to add.delay
- the timer delay.listenerToAdd
- an ActionListener to add before starting this timer.coalesce
- the coalesce state this Timer should work with.public void stop()
fireStateChanged()
.
If this Timer is already stopped, this method does nothing.