Get Global Mouse Pointer Location in Java in One Statement

global mouse location
Here is how to get global mouse pointer location in Java using a single statement. Yes, you heard it right, in a single statement!!
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


Posted by at on

Tags: Abstract Window Toolkit,