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_DRAGGEDThe mouse was moved over the component while a mouse button was held down
MouseEvent.MOUSE_ENTEREDThe cursor entered the component's space
MouseEvent.MOUSE_EXITEDThe cursor left the component's space
MouseEvent.MOUSE_MOVEDThe mouse moved in the component's space
MouseEvent.MOUSE_PRESSEDThe mouse button was pressed (but not released) over the component
MouseEvent.MOUSE_RELEASEDThe mouse button was released ever 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
Last Modified June 25, 1998
Copyright 1998 Elliotte Rusty Harold
elharo@sunsite.unc.edu