Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving the cursor in Java

Tags:

I want to make an app that measures the cursor's distance from the center of a component and then moves the cursor back to the center (like most PC video games do). Does anyone have any suggestions?

like image 628
Ky. Avatar asked Nov 20 '10 06:11

Ky.


People also ask

How do I move my cursor back in Java?

You can move the cursor of the ResultSet object to the previous row from the current position, using the previous() method of the ResultSet interface. This method returns a boolean value specifying whether the ResultSet object contains more rows.

What is robot in Java?

The primary purpose of Robot is to facilitate automated testing of Java platform implementations. Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue.


1 Answers

Robot class can do the trick for you. Here is a sample code for moving the mouse cursor:

try {     // These coordinates are screen coordinates     int xCoord = 500;     int yCoord = 500;      // Move the cursor     Robot robot = new Robot();     robot.mouseMove(xCoord, yCoord); } catch (AWTException e) { } 
like image 87
Faisal Feroz Avatar answered Oct 29 '22 10:10

Faisal Feroz