1

我试图在我想要的时候将鼠标移动到我的 JFrame 的中间。我原本以为我可以使用 Robot 将鼠标移动到所需的位置,但使用

robot.mouseMove(300, 400);

将鼠标移动到 300, 400,0, 0 作为我屏幕的左上角。我希望 0, 0 成为 JFrame 的左上角而不是整个屏幕。有没有人有任何想法?

4

1 回答 1

3

你试过吗?

JFrame frame = new JFrame();
frame.setLocation(100, 100);
frame.setSize(500, 500);
frame.setVisible(true);
try {
    Robot robot = new Robot();
    robot.mouseMove(frame.getX() + 250, frame.getY() + 250);
} catch (AWTException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

我试过了,这对我有用!

于 2013-05-16T23:46:35.303 回答