对于Java程序,我需要检测鼠标的单击。我导入了import java.awt.event.*;
。并运行:
public void mouseclicked(MouseEvent e)
{
if (e.getButton() == MouseEvent.BUTTON1)
{
System.out.println("Click position (X,Y): " + e.getX() + "," + e.getY());
}
}
运行此命令时,单击屏幕时没有任何输出。
这是我课程开始的样子:
class Drawing extends Canvas implements MouseListener,MouseMotionListener{
我不确定为什么会这样。我在Mac上,另一则帖子(JAVA mouseClicked event doesnt get fired on the Mac)暗示使用Mac可能有问题。