Java “.addActionListener(this)”

If I add a Action Listener then I always use the "this" between the brackets. But what does this "this" stand for ?!


The addActionListener method takes the current class object as a parameter. The "this" key word simply means "this object I'm working in right now". If you are using netbeans, you can type "this" and put a period after it to see all the methods defined in "this" class. It should list all the methods that are defined in your class including any inherited methods.

In order to fully understand what "this" means, you must first understand the relationship between classes and objects.

If you want to be technical about it, "this" is a reference to the current object.