• 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

Track all occurring events

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool that works perfect. Thanks for your help.
Eric
reply
    Bookmark Topic Watch Topic
  • New Topic