Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 ();

          //make something with the currentObj
Amir Kalron
Comment and Contribute






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



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