N/APosted on - 05/29/2015
I am trying to run an application in Java for a small project. As a start, i have to identify the position of the mouse pointer. how to detect the X location and Y location (X,Y) of the mouse pointer in Java ? This project will be a sub project later for a major project on which my team is working on. The user need not move the mouse, still the location of the mouse has to be identified and sent as a parameter to say a function Current_mouse_loc(). How to get the mouse pointer position? Which is the call back responsible for this? Thank you for replying.
How to get the position of current mouse pointer in Java
Note that both of these MouseEvent properties are read-only. The clientX and clientY properties are supported on the following web browsers: Google Chrome, Windows Internet Explorer, Mozilla Firefox, Safari, and Opera. The syntax to use the clientX property is “event.clientX”. See the example below.
var x = event.clientX; // Get the horizontal coordinate and store it in the variable x
var y = event.clientY; // Get the vertical coordinate and store it in the variable y
var coor = "X coords: " + x + ", Y coords: " + y;
When executed, the result of the variable coor might be:
X coords: 230, Y coords: 123