# Java: The Mouse

The mouse is handled automatically by most components, so you never have to know about it. For example, if someone clicks on a button (JButton), you will receive an ActionEvent, but you don't need to know (and shouldn't care) whether this was from a mouse click on the button, or from a keyboard shortcut.
Graphics. If you are are drawing your own graphics (eg, in a JPanel) and need to know where the user clicks, then you need to know about mouse events. You can easily add a mouse listener to a JPanel.

## Important Classes and Interfaces

These classes are defined in java.awt.event. The first three are the most commonly used.

- `MouseEvent` -- A MouseEvent object is passed to all mouse listeners. The most useful information in a MouseEvent is the x and y coordinates of the mouse cursor.
- `MouseListener` - Interface for mouse presses, releases, clicks, enters, and exits.
- `MouseMotionListener` - Interface for mouse moves and drags.
- `MouseInputListener` - Interface combination of MouseListener and MouseMotionListener.
- `MouseAdapter` -- Class useful for writing anonymous listener for mouse button presses, entering, ...
- `MouseMotionAdapter` -- Class useful for writing anonymous listener for mouse movement.

## Mouse Pages

- MouseListener - Handles presses, releases, clicks, enters, and exits.
- MouseMotionListener - Handles moves and drags.
- Mouse Listeners - How and where to write mouse listeners.
- Mouse Buttons, Modifier Keys - How to check which mouse buttons are pressed.
- Example - MouseTest.java - Example shows mouse coordinates.
- Example - DragDemo.java - Example shows mouse dragging.