• 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

Action Listeners

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question ID :955242516420 in JQ+
import java.awt.*;
public class TestClass extends Frame
{
Button b = new Button("OK");
TestClass()
{
add("South", b);
b.addActionListener( new MyListener("one") );
b.addActionListener( new MyListener("two") );
b.addActionListener( new MyListener("three") );
this.setSize(400, 400);
b.setVisible(true);
this.getLayout().layoutContainer(this);
this.setVisible(true);
}
public static void main(String[ ] args)
{
new TestClass();
}
class MyListener implements ActionListener
{
String name = "";
public MyListener(String str) { this.name = str; }
public void actionPerformed(ActionEvent ae)
{
System.out.println(name);
}
}
}

there were two options :
1. It will Print one two three but in an Unknown Order.
2. It will Print one two three in that Order.

The Correct Answer is 1 According to JQ+
But According to me Its Should be 2
Thanks in Advance
Navi
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Navi
Event handlers are not guaranteed to be called in the order they were added to a component. I can't locate the section in the jls that goes into it - maybe someone else can.

Dave
reply
    Bookmark Topic Watch Topic
  • New Topic