簡體   English   中英

如何在 JFrame 中設置 cursor 位置?

[英]How to set the cursor location in a JFrame?

我在 java swing 做一個小游戲,這是一個敵人跟隨 cursor 的游戲。 但是,如果 cursor 存在框架,應用程序將返回錯誤,因此當 cursor 離開 window 時,我讓應用程序退出。 但是實際上有沒有辦法直接設置cursor position?

它可以用於:

public static void moveMouse(JFrame jFrame, Point inside) throws AWTException {
        final GraphicsDevice device = jFrame.getGraphicsConfiguration().getDevice();
        final Robot r = new Robot(device);
        final Rectangle bounds = jFrame.getBounds();

        r.mouseMove(bounds.x + inside.x, bounds.y + inside.y);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM