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.

Mouse Pages