Difference between MouseListener and MouseMotionListener

by - October 21, 2017

They listen for different events:
mouseClicked(MouseEvent event)   // Called just after the user clicks the listened-to component.
mouseEntered(MouseEvent event)   // Called just after the cursor enters the bounds of the listened-to component.
mouseExited(MouseEvent event)    // Called just after the cursor exits the bounds of the listened-to component.
mousePressed(MouseEvent event)   // Called just after the user presses a mouse button while the cursor is over the listened-to component.
mouseReleased(MouseEvent event)  // Called just after the user releases a mouse button after a mouse press over the listened-to component
mouseDragged(MouseEvent event)   // Called in response to the user moving the mouse while holding a mouse button down. This event is fired by the component that fired the most recent mouse-pressed event, even if the cursor is no longer over that component.
mouseMoved(MouseEvent event)     // Called in response to the user moving the mouse with no
Add the listeners according to what event you're after.






You May Also Like

0 comments