PPT Slide
Registering Event Handlers
- To have Java use the event listener, you must tell Java to do so by registering the event
- To register a specific event, use addListener methods built into each component.
For example, a Button or MenuItem has the method:
addActionListener(ActionListener a)
to add an action listener to itself.
- Adding an action listener specifies that, whenever that Button or MenuItem gets an action event, it will call the method actionPerformed( ) on all the actionListeners that have
- Because interfaces are contracts, Java guarantees
that any class that implements the ActionListener
interface must provide code for actionPerformed( )