
If you do not register a lis-
tener on a component,the
component will not fire an
event.Thus,the event han-
dler will not execute when
the user interacts with the
component.
COMMON ERROR
TRAP
844 CHAPTER 12 Graphical User Interfaces
presses the Enter key, the component that is in focus will fire an action
event and our actionPerformed method will be executed.
We implement the actionPerformed method at lines 69–82. Because we
defined this event handler as a private inner class, the actionPerformed
method can directly access the id and password fields. At lines 71–72, we test
if the ID and password entered by the user are correct.
As shown in Table 12.9, the ...