final MouseListener myListener = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
// Die Maus ist in einer Komponente
System.out.println("Mouse entered component: "
+ e.getComponent().getName());
}
@Override
public void mouseExited(MouseEvent e) {
// Die Maus hat eine Komponente verlassen
System.out.println("Mouse exited component: "
+ e.getComponent().getName());
}
};
component.addMouseListener(myListener);
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent event) {
switch (event.getID()) {
case MouseEvent.MOUSE_ENTERED:
myListener.mouseEntered((MouseEvent) event);
break;
case MouseEvent.MOUSE_EXITED:
myListener.mouseExited((MouseEvent) event);
break;
case MouseEvent.MOUSE_PRESSED:
myListener.mousePressed((MouseEvent) event);
break;
case MouseEvent.MOUSE_RELEASED:
myListener.mouseReleased((MouseEvent) event);
break;
case MouseEvent.MOUSE_CLICKED:
myListener.mouseClicked((MouseEvent) event);
break;
}
}
}, AWTEvent.MOUSE_EVENT_MASK);