This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes button.addActionListener (this)   ???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "button.addActionListener (this)   ????" Watch "button.addActionListener (this)   ????" New topic
Author

button.addActionListener (this) ????

Dario Romani
Greenhorn

Joined: Oct 03, 2003
Posts: 13
Just reading through the User Interfaces that Swing - A Quick Start Guide tutorial at java.sun.com .
Early on they used an inline definition of the action listener using an anonympous inner class (see Example 2 of Turorial):

Then all of a sudden their code fragments switched to (see Example 3 and Example 4 of Tutorial):

Can someone explain what the syntax that utilizes "this" does?
Thanks.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9056
    
  12
Notice that

public class CelsiusConverter implements ActionListener

Therefore

button.addActionListener(this);

means that the actions for this ActionListener can be found in this class, the CelsiusConverter class.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: button.addActionListener (this) ????