Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on associating a listener to an object and having it stand-alone  RSS feed

 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought the listeners where pretty straight forward.
Create an object and associate it with a listener.

object1.addActionListener....
object2.addWindowListener....

But then I see the following code from another post.



I see the addWindowListener... but don't see it getting associated to an object.
Would have expected at the very least to see this.addWindowListener...
Is this one of those special cases where the listener is automatically associated to the object?
If so is this something specific to listeners?
Can anyone elaborate?
Thanks.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can invoke any method of the same class from a constructor or method without the necdessity to use the this keyword.

Just as you can use just dispose() and don't have to code it as this.dispose() in the listener's windowClosing(...)

In the latter case, the dispose method of the outer class is invoked.

edit: So yes, listeners are pretty straightforward.
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i think it was a silly oversight on my part.

Forgot that addWindowListener was inherited via Frame and by calling the addWindowListener it is being called from within itself and therefore adding the WindowListener to itself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!