Registering the Event Handler for Each Text Field
In the TextFieldFrame
constructor, line 42 creates a TextFieldHandler
object and assigns it to variable handler
. This object’s actionPerformed
method will be called automatically when the user presses Enter in any of the GUI’s text fields. However, before this can occur, the program must register this object as the event handler for each text field. Lines 43–46 are the event-registration statements that specify handler
as the event handler for the three JTextField
s and the JPasswordField
. The application calls JTextField
method addActionListener to register the event handler for each component. This method receives as its argument an ActionListener
object, which can be an object of any class ...
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.