Bookmark Topic Watch Topic
  • New Topic

How do I get this listener to wait for this other listener?  RSS feed

 
Clark Johnson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Report post to moderator
At a quick glance, that looks reasonable as long as you have access to the button variable. What doesn't it do?
 
Clark Johnson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Stan James:
At a quick glance, that looks reasonable as long as you have access to the button variable. What doesn't it do?


Someone already answered this question in the other forum. Turns out you don't need synchronization to do this.

All you have to do is:
1. Get the Object's listeners
2. Assign a reference of the original listener to a temp variable
3. Remove the Listeners
4. Add the new Listener
5. Add the original listener referenced to in the temp variable

That way, the original listener, the last listener added to the object, will be the one called first.
[ March 15, 2007: Message edited by: Clark Johnson ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't crosspost. Closing.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!