我正在完成斯坦福 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);
}