Previous | Next | Trail Map | To 1.1 -- And Beyond! | GUI Changes: The AWT Grows Up


Writing a Mouse Motion Listener

Mouse motion events tell you when the user uses the mouse (or a similar input device) to move the onscreen cursor. For information on tracking other mouse event types such as clicks, see Writing a Mouse Listener.

Mouse Motion Event Methods

The MouseMotionListener(in the API reference documentation) interface and its corresponding adapter class, MouseMotionAdapter(in the API reference documentation), contain two methods:
void mouseDragged(MouseEvent)
Called by the AWT in response to the user moving the mouse while holding a mouse button down. This event is fired by the component that fired the preceding mouse press event.
void mouseMoved(MouseEvent)
Called by the AWT in response to the user moving the mouse with no mouse buttons pressed. This event is fired by the listened-to component currently underneath the cursor. [CHECK]

Examples of Handling Mouse Motion Events

The following applet demonstrates mouse motion events. [describe applet]

[applet goes here]


Try this:
  1. Do something...

You can find the applet's code [nowhere yet]. Here is the applet's mouse motion event handling code:

[code goes here]

You can find more examples of mouse motion listeners in the following sections: [LIST GOES HERE]

The MouseEvent Class

Each mouse motion event method has a single parameter -- and it's not called MouseMotionEvent! Instead, mouse motion event methods use MouseEvent(in the API reference documentation) objects. See Writing a Mouse Listener for information about the MouseEvent class.


Previous | Next | Trail Map | To 1.1 -- And Beyond! | GUI Changes: The AWT Grows Up