Action Listeners In Tutorial 63

+1 Matt Walowski · May 7, 2015
When using action listeners how does the JActionListener know which action to listen for? For example in tutorial 63 when the button was pressed the code we wanted was performed but how did the program know we wanted that to happen on a click and not something else like when we press enter?

Post a Reply


Oldest  Newest  Rating
0 Nicholas Eason · May 7, 2015
ActionListener is coded to respond to Click events whereas, for Keyboard presses, you'd want a KeyListener. Similarly, a KeyListener requires the component to have focus, so even if ActionListener responded to key strokes, Bucky never requested focus on that button so it wouldn't work ;)
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator