Reputation: 63
I wanted to ask if there Is any way to get the Coordinates my coursor has within my window?
like "e.getX()" when using an Event, but without having to use an event?
or is there any sort of algorithm like getting the absolute position of the mouse and subtracting the position of the Frame?
Thanks Already and sorry for my bad english.
Upvotes: 3
Views: 4970
Reputation: 63
Ok Guys i found the solution now:
MouseInfo.getPointerInfo().getLocation().x - XYZ.getLocationOnScreen().x
MouseInfo.getPointerInfo().getLocation().y - XYZ.getLocationOnScreen().y
with XYZ being the reference to the Frame / Panel / whatever being used
Upvotes: 2
Reputation: 815
From what I can remember, I don't think there is a way to get the mouse coordinates without an event. I think your best bet is to use a public variable (mouseX, mouseY) and set them equal to event.getX() and event.getY(), that way, the mouse X and Y can be easily used throughout your program.
Upvotes: 0