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
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MenuDragMouseEvent, MouseWheelEvent

public class MouseEvent
extends InputEvent

Safe:

See Also:
Serialized Form

Field Summary
(package private)  int button
          Indicates which, if any, of the mouse buttons has changed state.
static int BUTTON1
          Enabled: Indicates mouse button #1; used by getButton().
static int BUTTON2
          Enabled: Indicates mouse button #2; used by getButton().
static int BUTTON3
          Enabled: Indicates mouse button #3; used by getButton().
(package private)  int clickCount
          Indicates the number of quick consecutive clicks of a mouse button.
static int MOUSE_CLICKED
          Enabled: The "mouse clicked" event.
static int MOUSE_DRAGGED
          Enabled: The "mouse dragged" event.
static int MOUSE_ENTERED
          Enabled: The "mouse entered" event.
static int MOUSE_EXITED
          Enabled: The "mouse exited" event.
static int MOUSE_FIRST
          Enabled: The first number in the range of ids used for mouse events.
static int MOUSE_LAST
          Enabled: The last number in the range of ids used for mouse events.
static int MOUSE_MOVED
          Enabled: The "mouse moved" event.
static int MOUSE_PRESSED
          Enabled: The "mouse pressed" event.
static int MOUSE_RELEASED
          Enabled: The "mouse released" event.
static int MOUSE_WHEEL
          Enabled: The "mouse wheel" event.
static int NOBUTTON
          Enabled: Indicates no mouse buttons; used by getButton().
(package private)  boolean popupTrigger
          A property used to indicate whether a Popup Menu should appear with a certain gestures.
private static long serialVersionUID
           
(package private)  int x
          The mouse event's x coordinate.
(package private)  int y
          The mouse event's y coordinate.
 
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, JDK_1_3_MODIFIERS, META_DOWN_MASK, META_MASK, modifiers, SHIFT_DOWN_MASK, SHIFT_MASK, when
 
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.awt.AWTEvent
ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK
 
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)
          Suppressed: Constructs a MouseEvent object with the specified source component, type, modifiers, coordinates, and click count.
MouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger, int button)
          Suppressed: Constructs a MouseEvent object with the specified source component, type, modifiers, coordinates, and click count.
 
Method Summary
 int getButton()
          Suppressed: Returns which, if any, of the mouse buttons has changed state.
 int getClickCount()
          Enabled: Returns the number of mouse clicks associated with this event.
static String getMouseModifiersText(int modifiers)
          Suppressed: Returns a String describing the modifier key(s), such as "Shift", or "Ctrl+Shift".
 Point getPoint()
          Enabled: Returns the x,y position of the event relative to the source component.
 int getX()
          Enabled: Returns the horizontal x position of the event relative to the source component.
 int getY()
          Enabled: Returns the vertical y position of the event relative to the source component.
private static void initIDs()
          Initialize JNI field and method IDs for fields that may be accessed from C.
 boolean isPopupTrigger()
          Enabled: Returns whether or not this mouse event is the popup menu trigger event for the platform.
 String paramString()
          Suppressed: Returns a parameter string identifying this event.
private  void readObject(ObjectInputStream s)
          Sets new modifiers by the old ones.
private  void setNewModifiers()
          Sets new modifiers by the old ones.
private  void setOldModifiers()
          Sets old modifiers by the new ones.
 void translatePoint(int x, int y)
          Enabled: Translates the event's coordinates to a new position by adding specified x (horizontal) and y (vertical) 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

MOUSE_FIRST

public static final int MOUSE_FIRST
Enabled: The first number in the range of ids used for mouse events.


MOUSE_LAST

public static final int MOUSE_LAST
Enabled: The last number in the range of ids used for mouse events.


MOUSE_CLICKED

public static final int MOUSE_CLICKED
Enabled: The "mouse clicked" event. This MouseEvent occurs when a mouse button is pressed and released.


MOUSE_PRESSED

public static final int MOUSE_PRESSED
Enabled: The "mouse pressed" event. This MouseEvent occurs when a mouse button is pushed down.


MOUSE_RELEASED

public static final int MOUSE_RELEASED
Enabled: The "mouse released" event. This MouseEvent occurs when a mouse button is let up.


MOUSE_MOVED

public static final int MOUSE_MOVED
Enabled: The "mouse moved" event. This MouseEvent occurs when the mouse position changes.


MOUSE_ENTERED

public static final int MOUSE_ENTERED
Enabled: The "mouse entered" event. This MouseEvent occurs when the mouse cursor enters the unobscured part of component's geometry.


MOUSE_EXITED

public static final int MOUSE_EXITED
Enabled: The "mouse exited" event. This MouseEvent occurs when the mouse cursor exits the unobscured part of component's geometry.


NOBUTTON

public static final int NOBUTTON
Enabled: Indicates no mouse buttons; used by getButton().

Since:
1.4

BUTTON1

public static final int BUTTON1
Enabled: Indicates mouse button #1; used by getButton().

Since:
1.4

BUTTON2

public static final int BUTTON2
Enabled: Indicates mouse button #2; used by getButton().

Since:
1.4

BUTTON3

public static final int BUTTON3
Enabled: Indicates mouse button #3; used by getButton().

Since:
1.4

MOUSE_DRAGGED

public static final int MOUSE_DRAGGED
Enabled: The "mouse dragged" event. This MouseEvent occurs when the mouse position changes while a mouse button is pressed.


MOUSE_WHEEL

public static final int MOUSE_WHEEL
Enabled: The "mouse wheel" event. This is the only MouseWheelEvent. It occurs when a mouse equipped with a wheel has its wheel rotated.

Since:
1.4

x

int x
The mouse event's x coordinate. The x value is relative to the component that fired the event.

See Also:
getX()

y

int y
The mouse event's y coordinate. The y value is relative to the component that fired the event.

See Also:
getY()

clickCount

int clickCount
Indicates the number of quick consecutive clicks of a mouse button. clickCount will be valid for only three mouse events :
MOUSE_CLICKED, MOUSE_PRESSED and MOUSE_RELEASED. For the above, the clickCount will be at least 1. For all other events the count will be 0.

See Also:
getClickCount().

button

int button
Indicates which, if any, of the mouse buttons has changed state. The only legal values are the following constants: NOBUTTON, BUTTON1, BUTTON2 or BUTTON3.

See Also:
getButton().

popupTrigger

boolean popupTrigger
A property used to indicate whether a Popup Menu should appear with a certain gestures. If popupTrigger = false, no popup menu should appear. If it is true then a popup menu should appear.

See Also:
java.awt.PopupMenu, isPopupTrigger()

serialVersionUID

private static final long serialVersionUID
Constructor Detail

MouseEvent

public MouseEvent(Component source,
                  int id,
                  long when,
                  int modifiers,
                  int x,
                  int y,
                  int clickCount,
                  boolean popupTrigger,
                  int button)
Suppressed: Constructs a MouseEvent object with the specified source component, type, modifiers, coordinates, and click count.

Note that passing in an invalid id results in unspecified behavior.

Parameters:
source - the Component that originated the event
id - the integer that identifies the event
when - a long int that gives the time the event occurred
modifiers - the modifier keys down during event (e.g. shift, ctrl, alt, meta) Either extended _DOWN_MASK or old _MASK modifiers should be used, but both models should not be mixed in one event. Use of the extended modifiers is preferred.
x - the horizontal x coordinate for the mouse location
y - the vertical y coordinate for the mouse location
clickCount - the number of mouse clicks associated with event
popupTrigger - a boolean, true if this event is a trigger for a popup menu
button - which of the mouse buttons has changed state. NOBUTTON, BUTTON1, BUTTON2 or BUTTON3.
Since:
1.4

MouseEvent

public MouseEvent(Component source,
                  int id,
                  long when,
                  int modifiers,
                  int x,
                  int y,
                  int clickCount,
                  boolean popupTrigger)
Suppressed: Constructs a MouseEvent object with the specified source component, type, modifiers, coordinates, and click count.

Note that passing in an invalid id results in unspecified behavior.

Parameters:
source - the Component that originated the event
id - the integer that identifies the event
when - a long int that gives the time the event occurred
modifiers - the modifier keys down during event (e.g. shift, ctrl, alt, meta) Either extended _DOWN_MASK or old _MASK modifiers should be used, but both models should not be mixed in one event. Use of the extended modifiers is preferred.
x - the horizontal x coordinate for the mouse location
y - the vertical y coordinate for the mouse location
clickCount - the number of mouse clicks associated with event
popupTrigger - a boolean, true if this event is a trigger for a popup menu
Method Detail

initIDs

private static void initIDs()
Initialize JNI field and method IDs for fields that may be accessed from C.


getX

public int getX()
Enabled: Returns the horizontal x position of the event relative to the source component.

Returns:
x an integer indicating horizontal position relative to the component

getY

public int getY()
Enabled: Returns the vertical y position of the event relative to the source component.

Returns:
y an integer indicating vertical position relative to the component

getPoint

public Point getPoint()
Enabled: Returns the x,y position of the event relative to the source component.

Returns:
a Point object containing the x and y coordinates relative to the source component

translatePoint

public void translatePoint(int x,
                           int y)
Enabled: Translates the event's coordinates to a new position by adding specified x (horizontal) and y (vertical) offsets.

Parameters:
x - the horizontal x value to add to the current x coordinate position
y - the vertical y value to add to the current y coordinate position

getClickCount

public int getClickCount()
Enabled: Returns the number of mouse clicks associated with this event.

Returns:
integer value for the number of clicks

getButton

public int getButton()
Suppressed: Returns which, if any, of the mouse buttons has changed state.

Since:
1.4

isPopupTrigger

public boolean isPopupTrigger()
Enabled: Returns whether or not this mouse event is the popup menu trigger event for the platform.

Note: Popup menus are triggered differently on different systems. Therefore, isPopupTrigger should be checked in both mousePressed and mouseReleased for proper cross-platform functionality.

Returns:
boolean, true if this event is the popup menu trigger for this platform

getMouseModifiersText

public static String getMouseModifiersText(int modifiers)
Suppressed: Returns a String describing the modifier key(s), such as "Shift", or "Ctrl+Shift". These strings can be localized by changing the awt.properties file.

Returns:
string a text description of the combination of modifier keys that were held down during the event
Since:
1.4

paramString

public String paramString()
Suppressed: Returns a parameter string identifying this event. This method is useful for event-logging and for debugging.

Overrides:
paramString in class ComponentEvent
Returns:
a string identifying the event and its attributes

setNewModifiers

private void setNewModifiers()
Sets new modifiers by the old ones. Also sets button.


setOldModifiers

private void setOldModifiers()
Sets old modifiers by the new ones.


readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
Sets new modifiers by the old ones.

IOException
ClassNotFoundException


comments?