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

doubt reg eventlisteners in awt classes?  RSS feed

 
mara thamizhan
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,

While programming in awt

why we should give (this) as parameter instead of giving the classname itself as parameter!

for example!

public class Sampleframe extends Frame
{
...
...

addactionListener(this);
...
...
....
}

Here i could have given addactionListener(Sampleframe)

why i should use this even if i hadnot created an object!

cheers,
Bye!
 
Campbell Ritchie
Sheriff
Posts: 53747
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hadnot created an object!
But you have created an object. The "this" you quote is usually in the middle of the constructor, so you do have an object.
And if you had two objects of the SampleFrame class, and then used "SampleFrame," which of the two objects would you be referring to?

The keyword "this" in Java refers back to the object you happen to be dealing with at the present; the more you program, the more useful you will find it.
[ July 22, 2006: Message edited by: Campbell Ritchie ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!