在Java中移动光标 [英] Moving the cursor in Java
本文介绍了在Java中移动光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个应用程序来测量光标与组件中心的距离,然后将光标移回中心(像大多数PC视频游戏一样)。有人有任何建议吗?
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?
推荐答案
机器人类可以为你做的伎俩。下面是一个移动鼠标光标的示例代码:
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) {
}
这篇关于在Java中移动光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文