This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
Joined: Sep 03, 2003
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.