MouseEvent class in java.awt.event package: Integer constants, Constructor, Methods

MouseEvent class in java.awt.event package handles events created when mouse is clicked, moved, and enters or exits a component. It is a sub class of InputEvent class.

Integer constants defined by MouseEvent class:

  • MOUSE_PRESSED: When mouse is pressed.
  • MOUSE_RELEASED: When mouse is released.
  • MOUSE_CLICKED: When mouse is clicked.
  • MOUSE_DRAGGED: When mouse is dragged.
  • MOUSE_ENTERED: When mouse entered a component.
  • MOUSE_EXITED: When mouse exited from a component.
  • MOUSE_MOVED: When mouse is moved.
  • MOUSE_WHEEL: When mouse wheel is moved.

Constructor defined by MouseEvent class:

By using source, type of event, when event was created, modifiers, coordinates of mouse, click count and triggersp to show if the event results in a popup menu.

MouseEvent(Component src, int type, long when, int modifiers, int x, int y, int clicks, boolean triggersp)

Methods defined by MouseEvent class:

getX( ) method: It is used to return the X coordinate of mouse.


int getX( )

getY( ) method: It is used to return the Y coordinate of mouse.


int getY( )

getPoint( ) method: It is used to return the X and Y coordinates of mouse.


Point getPoint( )

translatePoint( ) method: It is used to translate a point to another coordinate.


void translatePoint(int x, int y)

getClickCount( ) method: It is used to get number of clicks of mouse.


int getClickCount( )

isPopupTrigger( ) method: It is used to check if the event generates a popup menu.


boolean isPopupTrigger( )

getButton( ) method: It is used to find the button of mouse which resulted in the event.


int getButton( )

Constants defined by getButton( ) method: NOBUTTON, BUTTON1, BUTTON2, BUTTON3.

Leave a Reply