java - 光标相对于窗口的坐标
问题描述
我在游标类中有以下代码:
public void set()
{
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
x = (int)b.getX();
y = (int)b.getY()-windowSize;
x = (x/64)*64;
y = (y/64)*64;
}
它从屏幕本身而不是窗口读取坐标。我找到了一些使用 mouselistener 和 getPoint 的解决方案,但它必须在大型机类中声明,并且我无法通过继承或任何其他方式使 getPoint 在 set 函数中工作。我找到的所有解决方案都围绕着鼠标的某些动作,例如 MousePressed,但我需要每帧更新坐标。
任何帮助表示赞赏,我刚开始使用 Java 和 Swing,所以斗争是真实的......
解决方案
推荐阅读
- constraints - 不能对约束使用类型 dvar float+
- c++ - ZMQ 服务器/客户端模式
- python - Python SQLite3:连续两次执行查询时出现奇怪的NoneType问题
- javascript - 使用 CSS 可点击整个 div
- html - 手机无法点击链接
- mysql - 如何将任意数量的字符串传递给查询?
- amazon-dynamodb - 如何在 DynamoDB 上进行分片聚合
- ios - Xcode 9.3.1 组件列表为空,无法下载 iOS 10 模拟器
- angular - 在 Angular 中使用路由器时总是调用 NgOnInit
- c# - C# System.Drawing.Image.get_Width() 在 WinForms 窗体最大化时抛出异常