Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
Nov 15, 2002

Listening to All AWT Events


For some programs, it is helpful to create a listener to keep track of all the events being dispatched by the UI. This can be very useful in debugging programs. This is a way to listen to all such events in the Java environment.

Bascially, you implement AWTEventListener, which listens for all AWT events. To manipulate the object dispatching the events, just use the event method getSource () to retrieve the object. This code demonstrates how to listen to all mouse right-clicks:
 
 public class MySystemAWTEventListener implements AWTEventListener
{

   public MySystemAWTEventListener()
    {
    }


    /**
     * Invoked when an event is dispatched in the AWT.
     */
    public void eventDispatched(AWTEvent evt)
    {
      MouseEvent me = (MouseEvent)evt;
      currentObj  = me.getSource ();

      if(SwingUtilities.isRightMouseButton(me))
        {
          //make something with the currentObj
        }
    }
Amir Kalron
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date