Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.awt.event

Class MouseEvent

java.lang.Object
|
+--java.util.EventObject
   |
   +--java.awt.AWTEvent
      |
      +--java.awt.event.ComponentEvent
         |
         +--java.awt.event.InputEvent
            |
            +--java.awt.event.MouseEvent


public class MouseEvent

extends InputEvent

This event is generated for a mouse event. There are three main categories of mouse events: Regular events include pressing, releasing, and clicking buttons, as well as moving over the boundary of the unobscured portion of a component. Motion events include movement and dragging. Wheel events are covered separately by the subclass MouseWheelEvent.

A mouse event is tied to the unobstructed visible component that the mouse cursor was over at the time of the action. The button that was most recently pressed is the only one that shows up in getModifiers, and is returned by getButton, while all buttons that are down show up in getModifiersEx.

Drag events may be cut short if native drag-and-drop operations steal the event. Likewise, if a mouse drag exceeds the bounds of a window or virtual device, some platforms may clip the path to fit in the bounds of the component.

Since:Authors:See Also:

Field Summary

static intBUTTON1

This indicates that button 1 changed state.
static intBUTTON2

This indicates that button 2 changed state.
static intBUTTON3

This indicates that button 3 changed state.
static intMOUSE_CLICKED

This event id indicates that the mouse was clicked.
static intMOUSE_DRAGGED

This event id indicates that the mouse was dragged over a component.
static intMOUSE_ENTERED

This event id indicates that the mouse entered a component.
static intMOUSE_EXITED

This event id indicates that the mouse exited a component.
static intMOUSE_FIRST

This is the first id in the range of event ids used by this class.
static intMOUSE_LAST

This is the last id in the range of event ids used by this class.
static intMOUSE_MOVED

This event id indicates that the mouse was moved.
static intMOUSE_PRESSED

This event id indicates that the mouse was pressed.
static intMOUSE_RELEASED

This event id indicates that the mouse was released.
static intMOUSE_WHEEL

This event id indicates that the mouse wheel was rotated.
static intNOBUTTON

This indicates that no button changed state.

Constructor Summary

MouseEvent(java.awt.Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger, int button)

Initializes a new instance of MouseEvent with the specified information.
MouseEvent(java.awt.Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger)

Initializes a new instance of MouseEvent with the specified information.

Method Summary

intgetButton()

Returns which button, if any, was the most recent to change state.
intgetClickCount()

This method returns the number of mouse clicks associated with this event.
static java.lang.StringgetMouseModifiersText(int modifiers)

Returns a string describing the modifiers, such as "Shift" or "Ctrl+Button1".
java.awt.PointgetPoint()

This method returns a Point for the x,y position of the mouse pointer.
intgetX()

This method returns the X coordinate of the mouse position.
intgetY()

This method returns the Y coordinate of the mouse position.
booleanisPopupTrigger()

This method tests whether or not the event is a popup menu trigger.
java.lang.StringparamString()

Returns a string identifying this event.
voidtranslatePoint(int dx, int dy)

Translates the event coordinates by the specified x and y offsets.

Field Details

BUTTON1

public static final int BUTTON1

This indicates that button 1 changed state.

Since:See Also:


BUTTON2

public static final int BUTTON2

This indicates that button 2 changed state.

Since:See Also:


BUTTON3

public static final int BUTTON3

This indicates that button 3 changed state.

Since:See Also:


MOUSE_CLICKED

public static final int MOUSE_CLICKED

This event id indicates that the mouse was clicked.


MOUSE_DRAGGED

public static final int MOUSE_DRAGGED

This event id indicates that the mouse was dragged over a component.


MOUSE_ENTERED

public static final int MOUSE_ENTERED

This event id indicates that the mouse entered a component.


MOUSE_EXITED

public static final int MOUSE_EXITED

This event id indicates that the mouse exited a component.


MOUSE_FIRST

public static final int MOUSE_FIRST

This is the first id in the range of event ids used by this class.


MOUSE_LAST

public static final int MOUSE_LAST

This is the last id in the range of event ids used by this class.


MOUSE_MOVED

public static final int MOUSE_MOVED

This event id indicates that the mouse was moved.


MOUSE_PRESSED

public static final int MOUSE_PRESSED

This event id indicates that the mouse was pressed.


MOUSE_RELEASED

public static final int MOUSE_RELEASED

This event id indicates that the mouse was released.


MOUSE_WHEEL

public static final int MOUSE_WHEEL

This event id indicates that the mouse wheel was rotated.

Since:

NOBUTTON

public static final int NOBUTTON

This indicates that no button changed state.

Since:See Also:


Constructor Details

MouseEvent

public MouseEvent(java.awt.Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger)

Initializes a new instance of MouseEvent with the specified information. Note that an invalid id leads to unspecified results.

Parameters:

Throws:


MouseEvent

public MouseEvent(java.awt.Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger, int button)

Initializes a new instance of MouseEvent with the specified information. Note that an invalid id leads to unspecified results.

Since:Parameters:

Throws:


Method Details

getButton

public int getButton()

Returns which button, if any, was the most recent to change state. This will be one of #NOBUTTON, #BUTTON1, #BUTTON2, or #BUTTON3.

Since:Returns:


getClickCount

public int getClickCount()

This method returns the number of mouse clicks associated with this event.

Returns:


getMouseModifiersText

public static String getMouseModifiersText(int modifiers)

Returns a string describing the modifiers, such as "Shift" or "Ctrl+Button1". XXX Sun claims this can be localized via the awt.properties file - how do we implement that?

Parameters:

Returns:


getPoint

public Point getPoint()

This method returns a Point for the x,y position of the mouse pointer. This is relative to the source component.

Returns:


getX

public int getX()

This method returns the X coordinate of the mouse position. This is relative to the source component.

Returns:


getY

public int getY()

This method returns the Y coordinate of the mouse position. This is relative to the source component.

Returns:


isPopupTrigger

public boolean isPopupTrigger()

This method tests whether or not the event is a popup menu trigger. This should be checked in both MousePressed and MouseReleased to be cross-platform compatible, as different systems have different popup triggers.

Returns:


paramString

public String paramString()

Returns a string identifying this event. This is formatted as the field name of the id type, followed by the (x,y) point, the most recent button changed, modifiers (if any), extModifiers (if any), and clickCount.

Returns:


translatePoint

public void translatePoint(int dx, int dy)

Translates the event coordinates by the specified x and y offsets.

Parameters: