Java Reference
In-Depth Information
ods are called when the mouse interacts with a Component if appropriate event-listener ob-
jects are registered for that Component .
Each of the mouse event-handling methods receives as an argument a MouseEvent
object that contains information about the mouse event that occurred, including the x-
and y -coordinates of its location. These coordinates are measured from the upper-left corner
of the GUI component on which the event occurred. The x -coordinates start at 0 and
increase from left to right . The y -coordinates start at 0 and increase from top to bottom . The
methods and constants of class InputEvent ( MouseEvent 's superclass) enable you to deter-
mine which mouse button the user clicked.
MouseListener and MouseMotionListener interface methods
Methods of interface MouseListener
public void mousePressed(MouseEvent event)
Called when a mouse button is pressed while the mouse cursor is on a component.
public void mouseClicked(MouseEvent event)
Called when a mouse button is pressed and released while the mouse cursor remains sta-
tionary on a component. Always preceded by a call to mousePressed and mouseReleased .
public void mouseReleased(MouseEvent event)
Called when a mouse button is released after being pressed . Always preceded by a call to
mousePressed and one or more calls to mouseDragged .
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 while the mouse cursor is on a component and
the mouse is moved while the mouse button remains pressed . Always preceded by a call to
mousePressed . All drag events are sent to the component on which the user began to drag
the mouse.
public void mouseMoved(MouseEvent event)
Called when the mouse is moved (with no mouse buttons pressed) when the mouse cursor
is on a component. All move events are sent to the component over which the mouse is
currently positioned.
Fig. 12.27 | MouseListener and MouseMotionListener interface methods.
Software Engineering Observation 12.5
Calls to mouseDragged are sent to the MouseMotionListener for the Component on which
the drag started. Similarly, the mouseReleased call at the end of a drag operation is sent
to the MouseListener for the Component on which the drag operation started.
 
Search WWH ::




Custom Search