Here, src is a reference to the component that generated the event. The system time at which the mouse event occurred is passed in when.
The
modifiers argument indicates which modifiers were pressed when a mouse event occurred.
The coordinates of the mouse are passed in x and y. The click count is passed in clicks.
The
triggersPopup flag indicates if this event causes a pop-up menu to appear on this platform.
Two commonly used methods in this class are getX( ) and getY( ).
These return the X and
Y coordinates of the mouse within the component when the event occurred.
Point getPoint( )
It returns a Point object that contains the X,Y coordinates in its integer members: x and y.
The translatePoint( ) method changes the location of the event. Its form is shown here:
void translatePoint(int x, int y)
Here, the arguments x and y are added to the coordinates of the event.
The getClickCount( ) method obtains the number of mouse clicks for this event.
Its signature is shown here:
int getClickCount( )
The isPopupTrigger( ) method tests if this event causes a pop-up menu to appear on this
platform. Its form is shown here: boolean isPopupTrigger( )
int getButton( )
It returns a value that represents the button that caused the event. The return value will be
one of these constants defined by MouseEvent:
NOBUTTON
BUTTON1
BUTTON2
BUTTON3
The NOBUTTON value indicates that no button was pressed or released.
Java SE 6 added three methods to MouseEvent that obtain the coordinates of the mouse
relative to the screen rather than the component.
They are shown here:
Point getLocationOnScreen( )
int getXOnScreen( )
int getYOnScreen( )
The getLocationOnScreen( ) method returns a Point object that contains both the X and
Y coordinate. The other two methods return the indicated coordinate