Here is how to get global mouse pointer location in Java using a single statement. Yes, you heard it right, in a single statement!!
getLocation(): This method is present in the java.awt.PointerInfo class. The object for this class can be created using the getPointerInfo() method in the java.awt.MouseInfo class.
import java.awt.*;
class GetPointerLoc
{
public static void main(String args[])
{
// Get global current cursor location
Point p=MouseInfo.getPointerInfo().getLocation();
System.out.println(p);
}
}
getLocation(): This method is present in the java.awt.PointerInfo class. The object for this class can be created using the getPointerInfo() method in the java.awt.MouseInfo class.
Image credit: Iconarchive