1

我正在完成斯坦福 CS106A 讲座,并在突破性项目中遇到了障碍。

在 I 之后addMouseListeners(),我无法检测到 mouseMoved 调用。但是,如果我重命名mouseMoved()mouseDragged()ormouseClicked()mousePressed()等,它都会正确更新。只有移动的方法不起作用。没有错误或警报,只是没有检测到正在移动的鼠标。知道为什么会这样吗?

public void run() {
    /* Add a listener for the mouse */
    addMouseListeners();
    label = new GLabel("Mouse x & y");
    add(label, 50, 50);

    /* Load the method to create the brick pattern */
    createBricks();
}

/** Detect a mouse move and update something */
public void mouseMoved(MouseEvent e){
    label.setLabel("Mouse: " + e.getX() + " , " + e.getY());
    paddle.setLocation(e.getX(), getHeight()-PADDLE_Y_OFFSET);
}
4

1 回答 1

0

你需要使用addMouseMotionListeners();. addMouseListeners仅适用于您正在使用的功能。

于 2013-04-14T21:24:55.237 回答