Java examples for Swing:Mouse Event
get Mouse Position
//package com.java2s; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.MouseInfo; import java.awt.Point; public class Main { public static Point getMousePos(GraphicsDevice dev) { Point pos = MouseInfo.getPointerInfo().getLocation(); GraphicsConfiguration cfg = dev.getDefaultConfiguration(); int newX = pos.x - cfg.getBounds().x; int newY = pos.y - cfg.getBounds().y; return new Point(newX, newY); }//from ww w . ja va2 s . com }