October 2011
Beginner
432 pages
10h 18m
English
After you have implemented the interface needed for a particular component, you must set that component to generate user events. The ActionListener interface listens for action events, such as a button-click or the press of the Enter key. To make a JButton object generate an event, employ the addActionListener() method, as in the following:
Note
The this keyword confuses a lot of readers when they are first introduced to it. this refers to the object in which the keyword appears. So, if you create a LottoMadness class and use this in a statement inside that class, it refers to the LottoMadness object executing the code.
JButton fireTorpedos = new JButton("Fire torpedos");fireTorpedos.addActionListener(this ...
Read now
Unlock full access