import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; public class MouseHandler extends MouseAdapter { public void mouseClicked(MouseEvent e) { int xOnScreen = e.getXOnScreen(); System.out.println("Mouse clicked at x position " + xOnScreen); } }
import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; public class MouseHandler extends MouseMotionAdapter { public void mouseMoved(MouseEvent e) { int xOnScreen = e.getXOnScreen(); System.out.println("Mouse moved to x position " + xOnScreen); } }These examples are part of the java.awt.event package library.