如何获取Java应用程序的鼠标位置?
documentDOM.addEventListener("click", new EventListener() {
public void handleEvent(Event evt) {
if (evt.getType().equals("click")) {
System.out.println("hello");
MouseEvent mouseIvent = (MouseEvent) evt;
int screenX = mouseIvent.getXOnScreen();
int screenY = mouseIvent.getYOnScreen();
System.out.println("screen(X,Y) = " + screenX + "\t" + screenY);
}
}
}, true);
我需要在 Java 应用程序上找到特定的像素位置。该Java应用程序可以是窗口化的或最大化的窗口。
我的代码不知何故不返回整数。当 hello 消息被吐出时,这个事件就会触发。
documentDOM.addEventListener("click", new EventListener() {
public void handleEvent(Event evt) {
if (evt.getType().equals("click")) {
System.out.println("hello");
MouseEvent mouseIvent = (MouseEvent) evt;
int screenX = mouseIvent.getXOnScreen();
int screenY = mouseIvent.getYOnScreen();
System.out.println("screen(X,Y) = " + screenX + "\t" + screenY);
}
}
}, true);
I need to locate a specific pixel location on my Java application. This Java application can be windowed or maximized window.
My code somehow doesn't return the integers. this event does fire as hello message is spit out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关键是你必须添加一个 MouseListener 到将报告点击位置的组件:
The key is that you must add a MouseListener to the component which will report the click locations: