I'm trying to draw Polygons and would like to be able to click on my Frame to get MouseCoordinates so as to turn a mental Image into x/y values more quickly.
I'm using
System.out.println("("+ MouseInfo.getPointerInfo().getLocation().x +",
"+ MouseInfo.getPointerInfo().getLocation().y +")");
but this give me coordinates relative to my actual screen, and not my java window.
How can I make the coordinates show up relative to the Java Window?
You can convert between screen and component coordinates using the SwingUtilties class
The method convertPointFromScreen will take a screen coordinate and convert it to be relative to the component you provide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With