如何在Java中设置鼠标的位置? [英] How do I set the position of the mouse in Java?

查看:793
本文介绍了如何在Java中设置鼠标的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java进行一些Swing GUI工作,我认为我的问题相当简单;如何设置鼠标的位置?

I'm doing some Swing GUI work with Java, and I think my question is fairly straightforward; How does one set the position of the mouse?

推荐答案

你需要使用机器人


此类用于生成本机系统输入事件用于测试自动化,自运行演示以及需要控制鼠标和键盘的其他应用程序。 Robot的主要目的是促进Java平台实现的自动化测试。

This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.

使用类生成输入事件不同于将事件发布到AWT事件队列或AWT组件中事件是在平台的本机输入队列中生成的。例如, Robot.mouseMove 实际上会移动鼠标光标,而不仅仅是生成鼠标移动事件......

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. For example, Robot.mouseMove will actually move the mouse cursor instead of just generating mouse move events...

这篇关于如何在Java中设置鼠标的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆