Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use consume( ) in ActionEvent  RSS feed

 
Milind Kulkarni
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I see that it is possible to call consume() on a KeyEvent, but consume() is a protected method on ActionEvent. I have a menu item on my JFrame that kicks off a worker thread which will, among other things, add a new tab to a tabbed pane in my applet. I want to disable firing of an ActionEvent under some conditions. How do I implement consume() in this case? If you have any better ideas please let me know.
Regards,
Milind

[This message has been edited by Milind Kulkarni (edited August 11, 2000).]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm. The simplest solution might be to use MenuItem's method setEnabled() to disable the menu item completely when the conditions are met, and re-enable it when the condition are not met.
If that's not workable, then I'd be inclined to put the logic into the ActionListener(s) for the button. Let the ActionEvent be fired as normal, and let the ActionListener(s) decide whether to do anything about it. This would probably work best if there's only one ActionListener. If there's more than one class that needs to do something as a result of the ActionEvent, then let your single ActionListener be responsible for calling the appropriate methods in the other classes.
Another possibility is to create a new class extended from MenuItem which overrides processActionEvent():
<code><pre>
protected void processActionEvent(ActionEvent e) {
if (eventShouldBeConsumed() == false) {
super.processActionEvent(e);
}
}
</pre></code>
I think I like this last solution best, but I don't know if it works. Enjoy...
[This message has been edited by Jim Yingst (edited August 11, 2000).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!