Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Use AWTEventListener for Debugging Events (See related posts)

For debugging to help find where events are coming from, one can use AWTEventListeners to listen to all events that are dispatched. The following code shows an example that will print out the source component for all key events that are processed by AWT (and consequently Swing):

   1  
   2          Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
   3   
   4              public void eventDispatched(AWTEvent event) {
   5                  System.out.println(event.getSource());
   6   
   7              }
   8   
   9          }, AWTEvent.KEY_EVENT_MASK);

You need to create an account or log in to post comments to this site.


Click here to browse all 5521 code snippets

Related Posts