无法读取对ACM mouseMoved方法的调用

时间:2013-03-01 22:33:28

标签: java

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

addMouseListeners()之后,我无法检测到mouseMoved调用。 但是,如果我将mouseMoved()重命名为mouseDragged()mouseClicked()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);
}

1 个答案:

答案 0 :(得分:0)

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