Over a million developers have joined DZone.

Use AWTEventListener For Debugging Events

DZone's Guide to

Use AWTEventListener For Debugging Events

Free Resource
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):

        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
            public void eventDispatched(AWTEvent event) {
        }, AWTEvent.KEY_EVENT_MASK);

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}