This example emphasizes an event registration, but forgets event unregistration, therefore possibly leading to a MemoryLeak. This is the typical kind of code that teaches very bad habits to developers.
An
ActionListener is a sub-interface of
EventListener
- It allows an EventSource to know about all Listeners which want to be informed
When a user
- clicks a button
- doubleclicks a list item
- chooses a menu item
- presses return in a text field
example
button.addActionListener(this);
ActionListeners in
JavaSwing implement the
ActionListener interface with an
ActionListener.actionPerformed(
ActionEvent e) method defined which is called when an event (clicking a button, etc) takes place. They sort-of represent the controller in
ModelViewController. --
BrianMcCallister
In what way would you say they differ from the MVC controller?
Listeners are
MethodObjects.
They don't have to be.