Registering Events

Every JComponent has an instance variable called listenerList that refers to an object of class event-listenerList (package javax.swing.event). Each object of a JComponent subclass maintains references to its registered listeners in the listenerList. For simplicity, we’ve diagramed listenerList as an array below the JTextField object in Fig. 12.13.

Image

Fig. 12.13 | Event registration for JTextField textField1.

When the following statement (line 43 of Fig. 12.9) executes

textField1.addActionListener(handler);

a new entry containing a reference to the TextFieldHandler object is placed in textField1 ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.