MOUSE EVENT HANDLING

 

 

Mouse events can be trapped for any GUI component that derives from java.awt.Component. The methods of interfaces MouseListener and MouseMotionListener are summarized below

 

 

Methods of Interface MouseListener

 

public void mousePressed(MouseEvent event)

Called when a mouse button is pressed with the mouse cursor on a component.

 

 

public void mouseClicked(MouseEvent event)

Called when a mouse button is pressed and released on a component without moving the mouse cursor

 

 

public void mouseReleased(MouseEvent event)

Called when a mouse button is released after being pressed. This event is always preceded by a mousePressed event.

 

 

public void mouseEntered(MouseEvent event)

                        Called when the mouse cursor enters the bounds of a component.

 

 

public void mouseExited(MouseEvent event)

                        Called when the mouse cursor leaves the bounds of a component.

 

 

Methods of Interface MouseMotionListener

 

public void mouseDragged(MouseEvent event)

Called when the mouse button is pressed with the mouse cursor on a component and the mouse is moved. This event is always preceded by a call to mousePressed

 

 

public void mouseMoved(MouseEvent event)

                        Called when the mouse is moved with the mouse cursor on a component.

 

 

Example