• Post Reply Bookmark Topic Watch Topic
  • New Topic

Track all occurring events  RSS feed

 
Eric Hoskland
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'm running into a problem somewhere with events colliding or that they keep running when not supposed to.
Is there a way for me to output all the events that are occuring?
So like it prints keypressed when keypressed, mousereleased when mousereleased, FocusGained when Focus Gained, etc...
Eric
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once upon a time, in Java 1.0, unhandled events propogated up the containment hierarchy until they were dealt with. That would be _perfect_ for what you are trying to do. Unfortunately it was tedious for doing anything else (i.e. to catch a button's event you either had to subclass it or find its event in one of its containers), so Java 1.1 changed to a subscriber method of event handling, so your best bet is to create a class that implements all listeners and subscribe to all your GUI's component's events. It may be worth it to look into a graphical debugger and try to put breakpoints on all the GUI components' fire*Event methods.
 
praveen kumar gudapati
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As swing is single threaded, all events get queued in EventQueue class.
That mean all events pass through dispatchEvent method of this class.
By just overriding the dispatchEvent method in EventQueue class and setting the inherited class as SystemEventQueue you can capture all events occuring in swing.

public class XXEventQueue extends EventQueue {
protected void dispatchEvent(AWTEvent event) {
super.dispatchEvent(event);
// You can capture all events here
}
}
After that set instance of the above class as the actual EventQueue
Toolkit.getDefaultToolkit().getSystemEventQueue().push(new XXEventQueue());
Have fun
 
Eric Hoskland
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool that works perfect. Thanks for your help.
Eric
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!