|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.EventObject
java.awt.AWTEvent
java.awt.event.ComponentEvent
java.awt.event.InputEvent
java.awt.event.MouseEvent
public class MouseEvent
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.
MouseAdapter
,
MouseListener
,
MouseMotionAdapter
,
MouseMotionListener
,
MouseWheelListener
,
Serialized FormField Summary | |
---|---|
static int |
BUTTON1
This indicates that button 1 changed state. |
static int |
BUTTON2
This indicates that button 2 changed state. |
static int |
BUTTON3
This indicates that button 3 changed state. |
static int |
MOUSE_CLICKED
This event id indicates that the mouse was clicked. |
static int |
MOUSE_DRAGGED
This event id indicates that the mouse was dragged over a component. |
static int |
MOUSE_ENTERED
This event id indicates that the mouse entered a component. |
static int |
MOUSE_EXITED
This event id indicates that the mouse exited a component. |
static int |
MOUSE_FIRST
This is the first id in the range of event ids used by this class. |
static int |
MOUSE_LAST
This is the last id in the range of event ids used by this class. |
static int |
MOUSE_MOVED
This event id indicates that the mouse was moved. |
static int |
MOUSE_PRESSED
This event id indicates that the mouse was pressed. |
static int |
MOUSE_RELEASED
This event id indicates that the mouse was released. |
static int |
MOUSE_WHEEL
This event id indicates that the mouse wheel was rotated. |
static int |
NOBUTTON
This indicates that no button changed state. |
Fields inherited from class java.awt.event.InputEvent |
---|
ALT_DOWN_MASK, ALT_GRAPH_DOWN_MASK, ALT_GRAPH_MASK, ALT_MASK, BUTTON1_DOWN_MASK, BUTTON1_MASK, BUTTON2_DOWN_MASK, BUTTON2_MASK, BUTTON3_DOWN_MASK, BUTTON3_MASK, CTRL_DOWN_MASK, CTRL_MASK, META_DOWN_MASK, META_MASK, SHIFT_DOWN_MASK, SHIFT_MASK |
Fields inherited from class java.awt.event.ComponentEvent |
---|
COMPONENT_FIRST, COMPONENT_HIDDEN, COMPONENT_LAST, COMPONENT_MOVED, COMPONENT_RESIZED, COMPONENT_SHOWN |
Fields inherited from class java.util.EventObject |
---|
source |
Constructor Summary | |
---|---|
MouseEvent(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. |
|
MouseEvent(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(Component source,
int id,
long when,
int modifiers,
int x,
int y,
int absX,
int absY,
int clickCount,
boolean popupTrigger,
int button)
Creates a new MouseEvent. |
Method Summary | |
---|---|
int |
getButton()
Returns which button, if any, was the most recent to change state. |
int |
getClickCount()
This method returns the number of mouse clicks associated with this event. |
Point |
getLocationOnScreen()
|
static String |
getMouseModifiersText(int modifiers)
Returns a string describing the modifiers, such as "Shift" or "Ctrl+Button1". |
Point |
getPoint()
This method returns a Point for the x,y position of
the mouse pointer. |
int |
getX()
This method returns the X coordinate of the mouse position. |
int |
getXOnScreen()
|
int |
getY()
This method returns the Y coordinate of the mouse position. |
int |
getYOnScreen()
|
boolean |
isPopupTrigger()
This method tests whether or not the event is a popup menu trigger. |
String |
paramString()
Returns a string identifying this event. |
void |
translatePoint(int dx,
int dy)
Translates the event coordinates by the specified x and y offsets. |
Methods inherited from class java.awt.event.InputEvent |
---|
consume, getModifiers, getModifiersEx, getModifiersExText, getWhen, isAltDown, isAltGraphDown, isConsumed, isControlDown, isMetaDown, isShiftDown |
Methods inherited from class java.awt.event.ComponentEvent |
---|
getComponent |
Methods inherited from class java.awt.AWTEvent |
---|
getID, setSource, toString |
Methods inherited from class java.util.EventObject |
---|
getSource |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MOUSE_FIRST
public static final int MOUSE_LAST
public static final int MOUSE_CLICKED
public static final int MOUSE_PRESSED
public static final int MOUSE_RELEASED
public static final int MOUSE_MOVED
public static final int MOUSE_ENTERED
public static final int MOUSE_EXITED
public static final int NOBUTTON
getButton()
,
Constant Field Valuespublic static final int BUTTON1
getButton()
,
Constant Field Valuespublic static final int BUTTON2
getButton()
,
Constant Field Valuespublic static final int BUTTON3
getButton()
,
Constant Field Valuespublic static final int MOUSE_DRAGGED
public static final int MOUSE_WHEEL
Constructor Detail |
---|
public MouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger, int button)
MouseEvent
with the specified
information. Note that an invalid id leads to unspecified results.
source
- the source of the eventid
- the event idwhen
- the timestamp of when the event occurredmodifiers
- the modifier keys during the event, in old or new stylex
- the X coordinate of the mouse pointy
- the Y coordinate of the mouse pointclickCount
- the number of mouse clicks for this eventpopupTrigger
- true if this event triggers a popup menubutton
- the most recent mouse button to change state
IllegalArgumentException
- if source is null or button is invalidpublic MouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger)
MouseEvent
with the specified
information. Note that an invalid id leads to unspecified results.
source
- the source of the eventid
- the event idwhen
- the timestamp of when the event occurredmodifiers
- the modifier keys during the event, in old or new stylex
- the X coordinate of the mouse pointy
- the Y coordinate of the mouse pointclickCount
- the number of mouse clicks for this eventpopupTrigger
- true if this event triggers a popup menu
IllegalArgumentException
- if source is nullpublic MouseEvent(Component source, int id, long when, int modifiers, int x, int y, int absX, int absY, int clickCount, boolean popupTrigger, int button)
source
- the source of the eventid
- the event idwhen
- the timestamp of when the event occurredmodifiers
- the modifier keys during the event, in old or new stylex
- the X coordinate of the mouse pointy
- the Y coordinate of the mouse pointabsX
- the absolute X screen coordinate of this eventabsY
- the absolute Y screen coordinate of this eventclickCount
- the number of mouse clicks for this eventpopupTrigger
- true if this event triggers a popup menubutton
- the most recent mouse button to change state
IllegalArgumentException
- if source is null or button is invalidMethod Detail |
---|
public int getX()
public int getY()
public Point getLocationOnScreen()
public int getXOnScreen()
public int getYOnScreen()
public Point getPoint()
Point
for the x,y position of
the mouse pointer. This is relative to the source component.
Point
for the event positionpublic void translatePoint(int dx, int dy)
dx
- the value to add to the X coordinate of this eventdy
- the value to add to the Y coordiante of this eventpublic int getClickCount()
public int getButton()
NOBUTTON
, BUTTON1
, BUTTON2
, or
BUTTON3
.
public boolean isPopupTrigger()
public static String getMouseModifiersText(int modifiers)
modifiers
- the old-style modifiers to convert to text
public String paramString()
paramString
in class ComponentEvent
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |