SWING - MouseEvent Class

This event indicates that a mouse action occurred in a component. This low-level event is generated by a component object for Mouse Events and Mouse motion events. This event is generated when −
A mouse button is pressed.
A mouse button is pressed.
A mouse button is released.
A mouse button is released.
A mouse button is clicked (pressed and released).
A mouse button is clicked (pressed and released).
A mouse cursor enters the unobscured part of component's geometry.
A mouse cursor enters the unobscured part of component's geometry.
A mouse cursor exits the unobscured part of component's geometry.
A mouse cursor exits the unobscured part of component's geometry.
A mouse is moved.
A mouse is moved.
A mouse is dragged.
A mouse is dragged.
Following is the declaration for java.awt.event.MouseEvent class −
public class MouseEvent
   extends InputEvent

Following are the fields for java.awt.event.MouseEvent class −
static int BUTTON1 − Indicates mouse button #1; used by getButton()
static int BUTTON1 − Indicates mouse button #1; used by getButton()
static int BUTTON2 − Indicates mouse button #2; used by getButton()
static int BUTTON2 − Indicates mouse button #2; used by getButton()
static int BUTTON3 − Indicates mouse button #3; used by getButton()
static int BUTTON3 − Indicates mouse button #3; used by getButton()
static int MOUSE_CLICKED − The "mouse clicked" event
static int MOUSE_CLICKED − The "mouse clicked" event
static int MOUSE_DRAGGED − The "mouse dragged" event
static int MOUSE_DRAGGED − The "mouse dragged" event
static int MOUSE_ENTERED − The "mouse entered" event
static int MOUSE_ENTERED − The "mouse entered" event
static int MOUSE_EXITED − The "mouse exited" event
static int MOUSE_EXITED − The "mouse exited" event
static int MOUSE_FIRST − The first number in the range of IDs used for mouse events
static int MOUSE_FIRST − The first number in the range of IDs used for mouse events
static int MOUSE_LAST − The last number in the range of IDs used for mouse events
static int MOUSE_LAST − The last number in the range of IDs used for mouse events
static int MOUSE_MOVED − The "mouse moved" event
static int MOUSE_MOVED − The "mouse moved" event
static int MOUSE_PRESSED − The "mouse pressed" event
static int MOUSE_PRESSED − The "mouse pressed" event
static int MOUSE_RELEASED − The "mouse released" event
static int MOUSE_RELEASED − The "mouse released" event
static int MOUSE_WHEEL − The "mouse wheel" event
static int MOUSE_WHEEL − The "mouse wheel" event
static int NOBUTTON − Indicates no mouse buttons; used by getButton()
static int NOBUTTON − Indicates no mouse buttons; used by getButton()
static int VK_WINDOWS − Constant for the Microsoft Windows "Windows" key.
static int VK_WINDOWS − Constant for the Microsoft Windows "Windows" key.
MouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger)
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)
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 xAbs, int yAbs, int clickCount, boolean popupTrigger, int button)
Constructs a MouseEvent object with the specified source component, type, modifiers, coordinates, absolute coordinates, and click count.
int getButton()
Returns which, if any, of the mouse buttons has changed state.
int getClickCount()
Returns the number of mouse clicks associated with this event.
Point getLocationOnScreen()
Returns the absolute x, y position of the event.
static String getMouseModifiersText(int modifiers)
Returns a String describing the modifier keys and mouse buttons that were down during the event, such as "Shift", or "Ctrl+Shift".
Point getPoint()
Returns the x,y position of the event relative to the source component.
int getX()
Returns the horizontal x position of the event relative to the source component.
int getXOnScreen()
Returns the absolute horizontal x position of the event.
int getY()
Returns the vertical y position of the event relative to the source component.
int getYOnScreen()
Returns the absolute vertical y position of the event.
boolean isPopupTrigger()
Returns whether or not this mouse event is the popup menu trigger event for the platform.
String paramString()
Returns a parameter string identifying this event.
void translatePoint(int x, int y)
Translates the event's coordinates to a new position by adding specified x (horizontal) and y (vertical) offsets.
This class inherits methods from the following classes −
java.awt.event.InputEvent
java.awt.event.ComponentEvent
java.awt.AWTEvent
java.util.EventObject
java.lang.Object

    30 Lectures 
     3.5 hours 

 Pranjal Srivastava

    13 Lectures 
     1 hours 

 Pranjal Srivastava

    25 Lectures 
     4.5 hours 

 Emenwa Global, Ejike IfeanyiChukwu

    14 Lectures 
     1.5 hours 

 Travis Rose

    14 Lectures 
     1 hours 

 Travis Rose
 Print
 Add Notes
 Bookmark this page