I am working with a "Frame" object (see below) which I am not allowed to modify. The JButton in this Frame has its own listener. I need to add a new ActionListener to this button in order to expand its functionality. I can't get this to work the way I want it to, and I think it's due to a synchronization problem. Please look at the following code and tell me what I can do to achieve my goal.
Get rid of "public class A." Just call it the main method inside the class Frame.
Change the access of class Frame to public.
Add the line following after "addActionListener" in the main method:-
JOptionPane.showMessageDialog(frame, frame.button.getActionListeners(), "ActionListeners in main", JOptionPane.INFORMATION_MESSAGE);
Add the following similar line after addActionListener in the constructor:-
JOptionPane.showMessageDialog(this, button.getActionListeners(), "ActionListeners in constructor", JOptionPane.INFORMATION_MESSAGE);
I got two JOptionPanes, one saying Frame$1@901887, the second Frame$2@b1937c Frame1@901887. Obviously their hashCodes. Don't know whether this means no 2 was added before no 1. Then I get this output on the shell:-
and the button changes from "I want this to wait . . ." to "Number: 9999999" after a few seconds.
Might be because the ActionListeners are added in stack order (first in, last out), but otherwise I am not sure what I can suggest which would make any difference if you aren't allowed to change Frame.
Joined: Mar 08, 2007
Might be because the ActionListeners are added in stack order (first in, last out), but otherwise I am not sure what I can suggest which would make any difference if you aren't allowed to change Frame.[/QB]
Hello Campbell. As you pointed out in the paragraph above, I am not allowed to modify the Frame class (the class I am working with is more complex than the sample class posted above). The Frame class is what it is and I need work with what I have. Thanks for taking the time to look into this.
Does anyone have any idea as to how I can solve this problem? How many of you say synchronization will solve my problem?