• 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

getSource() method of an ActionEvent

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Which statement about the getSource() method of an ActionEvent is true?
A It is used to identify a component affected by an action.
B It is used to identify the cause of an action on a component.
C It is used to identify the panel of a component affected by an action.
D It is used to identify the frame of a component affected by an action.
ans:
Option A is correct because the getSource() method is used to identify an object on which an event occurred.
Option B is incorrect because the getSource() method will not identify the cause of an action on a component.
Options C and D are incorrect because the getSource() method does not identify the panel or frame of a
component affected by an action.
i thought it was b
is this method in ActionEvent or EventObject grrr
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is based on my learning from Khalid Mughal's book...
Object getSource() is defined in the java.util.EventObject class. It returns the object that originated the event.
I think you have confused this method with the int getID() method defined in the abstract class java.awt.AWTEvent. This AWTEvent is the superclass of all AWT related classes.
The method getID() returns an ID in the form of an integer value that identifies the type of the event. For example, the MouseEvent has various events...Mouse button being clicked(MouseEvent.MOUSE_CLICKED), Mouse being dragged(MouseEvent.MOUSE_DRAGGED)etc., The values MouseEvent.MOUSE_CLICKED , MouseEvent.MOUSE_DRAGGED etc., represent an ID for the event. The getID() method returns this ID.
Another interesting point...
There exists a method in the Component class : Component getComponent() . It returns a reference to the same object as the getSource() method, but the returned reference if of the type Component.
Hope this helps
Shyam
[This message has been edited by Shyamsundar Gururaj (edited October 28, 2001).]
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic