• Post Reply Bookmark Topic Watch Topic
  • New Topic

Event handlers question  RSS feed

 
Vonique Leary
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm on event handlers now, and as usual, can't figure something out:

From what I've understood til now, "e", which is of type ActionEvent, is a parameter for the method actionPerformed. But my book says that "e" is a reference to the object (in this case a checkbox) that is performing the event that actionPerformed is listening for. How can "e" be a reference to the checkbox when it is an object of type ActionEvent? I guess I'm really missing something.

Can anyone explain it to me?

Thanks, Von
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

"e" is that first thing -- the event -- and not the object that the event is directed to. But you can call the method "getSource()" on e, and that will give you the object the event is acting on. So if you attach an ActionListener to a bunch of buttons, then inside your method, for example, you could...


 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic is usually discussed on the Swing forum. Moving.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!