The MouseEvent event is used by two different interfaces:
java.awt.event.MouseListener and java.awt.event.MouseMotionListener. The first interface is designed to process events button press and mouse detection entrance and exit of a mouse over a component. The second is the processing the mouse movement.
The java.awt.event.MouseListener interface requires the implementation of severalmethods : mousePressed, mouseReleased, mouseEntered, and mouseExitedmouseClicked. To reduce the amount of required code can opt for the extension of the class java.awt.event.MouseAdapter that provides a null implementation of the above methods.
The java.awt.event.MouseMotionListener interface requires the implementation of following methods : mouseDragged and mouseMoved . As for the interface MouseListener, can opt for the extension of the class to MouseMotionAdapter reducing the amount of code required . The MouseEvent event has the following specific methods :
Returns the number of clicks associated with this event.
Returns a Point object containing the coordinates of where the activation of the mouse occurred.
Returns the x coordinate of where they occurred Pressing the mouse.
Returns the y coordinate of where they occurred Pressing the mouse.
Checks if this event is associated with display Popup menus on this platform.
TranslatePoint (int, int)
Translates the coordinate of the event with the values specified.
/* <APPLET CODE ="MouselistenerJavaAwt.class" WIDTH=300 HEIGHT=200> </APPLET> */
public class MouselistenerJavaAwt extends Applet implements MouseListener
public void init()
public void mousePressed(MouseEvent e)
t.setText("Mouse Pressed; # of clicks:"+e.getClickCount()+"at position"+e.getX()+","+e.getY());
public void mouseReleased(MouseEvent e)
t.setText("Mouse Released; # of clicks:"+e.getClickCount());
public void mouseEntered(MouseEvent e)
public void mouseExited(MouseEvent e)
public void mouseClicked(MouseEvent e)
t.setText("mouse clicked(# of clicks:"+e.getClickCount());