Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusing question on action performed

 
Vishy Karl
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi:
The answer is D because the excution depends on the schedular of the JVM.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AWT questions will not be present in the 1.4 exam.
 
Steve Lovelace
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Steve Lovelace
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic