Ask Questions?

View Latest Questions

Advertisement


 
 

The Mouse
Posted on: July 26, 2006 at 12:00 AM
The mouse is handled automatically by most components, so you never have to know about it.

Java Notes

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

Copyleft 2003 Fred Swartz MIT License, Last update: 2003-10-30
Advertisement


DMCA.com