首页 > 解决方案 > 光标相对于窗口的坐标

问题描述

我在游标类中有以下代码:

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,所以斗争是真实的......

标签: javaswingcursorcursor-position

解决方案


推荐阅读