File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confusing question on action performed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confusing question on action performed" Watch "confusing question on action performed" New topic
Author

confusing question on action performed

Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
Hi there,
Just got the following question in a mock which is very unclear to me

Question 15.
Given that 6 action Listeners are added to a button, which action Listener is the first one to get its actionPerformed(), method invoked when button is pressed.
A.The first ActionListener that was added to button first gets
its actionPerformed invoked first.
B.It depends on the platform on which we are running the code.
C.A seperate thread will be created for each actionPerformed
method to run and they run concurrently.
D.It is imposible to know which listener will be first to
get its actionPerformed invoked.
The answer given is D.
But my question is that isn't the order of the action listeners fixed ?

can u explain to me why Answer D is correct ?
thanks in advance.


"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi:
The answer is D because the excution depends on the schedular of the JVM.


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
AWT questions will not be present in the 1.4 exam.


Tony Morris
Java Q&A (FAQ, Trivia)
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
MK:
Pretty sure you are right. Multiple ActionListeners added to a Button are linked together in a chain of AWYEventMulticasters. When the Button processes an ActionEvent, it executes the actionPerformed() method on the root of the chain, which causes invocation on each listener, which necessarily means in the order of their addition to the chain. So the question seems to be out to sea on this.
[ September 27, 2003: Message edited by: Steve Lovelace ]

The Inner that is named is not the true Inner.
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
Just checked to see what Swing is doing. It uses a different mechanism from AWT (an EventListener list as opposed an AWTEventMultiCaster chain), and while the order is still fixed, it goes in the opposit direction: from last added to first. This would apply to any subclass of AbstractButton.(Someone please correct me if I've got one or both of these wrong.)
There is the possiblity that a programmer has decided to subclass a button of some type and provide custom event processing. That would be way off track for a question like this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confusing question on action performed
 
Similar Threads
which listener first ?
Showing a series of records
listeners
Help.....Questions from Mock Exam
Reg. Action Listener