diff options
Diffstat (limited to 'libjava/javax/swing/Timer.java')
-rw-r--r-- | libjava/javax/swing/Timer.java | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/libjava/javax/swing/Timer.java b/libjava/javax/swing/Timer.java index 80eb13a..89df756 100644 --- a/libjava/javax/swing/Timer.java +++ b/libjava/javax/swing/Timer.java @@ -47,12 +47,13 @@ import javax.swing.event.EventListenerList; public class Timer implements Serializable { + protected EventListenerList listenerList = new EventListenerList(); + int ticks; static boolean verbose; boolean running; boolean repeat_ticks = true; long interval, init_delay; - Vector actions = new Vector(); class Waker extends Thread { @@ -86,23 +87,44 @@ public class Timer implements Serializable public void addActionListener(ActionListener listener) { - actions.addElement(listener); + listenerList.add (ActionListener.class, listener); } + public void removeActionListener(ActionListener listener) { - actions.removeElement(listener); + listenerList.remove (ActionListener.class, listener); + } + + /** + * @since 1.3 + */ + public EventListener[] getListeners (Class listenerType) + { + return listenerList.getListeners (listenerType); + } + + /** + * @since 1.4 + */ + public ActionListener[] getActionListeners () + { + return (ActionListener[]) listenerList.getListeners (ActionListener.class); } - void fireActionPerformed() + protected void fireActionPerformed (ActionEvent event) { - for (int i=0;i<actions.size();i++) + ActionListener[] listeners = getActionListeners(); + + for (int i = 0; i < listeners.length; i++) { - ActionListener a = (ActionListener) actions.elementAt(i); - a.actionPerformed(new ActionEvent(this, ticks, "Timer")); + listeners [i].actionPerformed (event); } } - + void fireActionPerformed () + { + fireActionPerformed (new ActionEvent (this, ticks, "Timer")); + } public static void setLogTimers(boolean flag) { |