Mouse Events

A java.awt.event.MouseEvent is sent to a component when the mouse state changes over the component. There are seven types of mouse events, each represented by an integer constant:

MouseEvent.MOUSE_CLICKED A mouse button was pressed, then released
MouseEvent.MOUSE_DRAGGED The mouse was moved over the component while a mouse button was held down
MouseEvent.MOUSE_ENTERED The cursor entered the component's space
MouseEvent.MOUSE_EXITED The cursor left the component's space
MouseEvent.MOUSE_MOVED The mouse moved in the component's space
MouseEvent.MOUSE_PRESSED The mouse button was pressed (but not released) over the component
MouseEvent.MOUSE_RELEASED The mouse button was released over the component.

Besides its type, the main thing you want to know about a MouseEvent is the location; that is, where the mouse was clicked. You can either request the x and y locations separately, or together as a java.awt.Point object.

 public int getX()
 public int getY()
 public Point getPoint()

Previous | Next | Top | Cafe au Lait

Copyright 1998, 2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 26, 2006