• 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

confusing question on action performed

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi:
The answer is D because the excution depends on the schedular of the JVM.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AWT questions will not be present in the 1.4 exam.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic