public void mouseMoved(MouseEvent e) { Point p = e.getPoint(); System.out.println("Mouse moved at x=" + p.getX() + ", y=" + p.getY()); }
public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { performAction(e.getPoint()); } }This code snippet performs an action when the left mouse button is clicked over the component. The MouseEvent object is used to call the getButton() method and check if the left mouse button is pressed. If it is, the performAction() method is called with the Point object obtained from the getPoint() method as its argument. This example is used to execute an action when a mouse button is pressed, and the package library used is the java.awt.event package.