• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

button.addActionListener (this) ????

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic