Hello, I have a question about the method actionPerformed(ActionEvent e); In many times, we will specify the following statement :
But I have some confuse about that : We have already specify the object "button" itself, why we have to use "this" as the argument of the addActionListener() method ? Why we have to emphasize button and this to indicate button object itself？
"this" doesn't refer to the button, but rather it refers to the current class, and for this to work, the class must implement the ActionListener interface and in doing so, must have an actionPerformed(ActionEvent e) method. When the button is pressed, it will run the actionPerformed method of the ActionListener object that was loaded into it by this method.
Having said all this, I couldn't agree more with Campbell Ritchie's recommendation. Don't get in the habit of passing "this" as the ActionListener, but rather use specific ActionListener objects which can be anonymous inner class objects, private inner class objects, or standard class objects.
If you look closely at this tiny ad, you will see five bicycles and a naked woman: