[英]Mouse Click Listener doesn't fire
I am following a tutorial here I absolutely did the same thing but when I clicked the mouse buttons nothing happens. 我在这里遵循一个教程我绝对做了同样的事情但是当我点击鼠标按钮时没有任何反应。 I tried to debug but I don't know how to do that.
我试着调试,但我不知道该怎么做。
class MouseClickListener extends MouseAdapter{
public void MouseClicked(MouseEvent e){
if(SwingUtilities.isLeftMouseButton(e)){
System.out.print("Left clicked");
}
else if(SwingUtilities.isRightMouseButton(e)){
System.out.print("Right Clicked");
System.out.print("sssss");
}
else if(SwingUtilities.isMiddleMouseButton(e)){
System.out.print("Middle clicked");
}
System.out.print(e.getClickCount()+"times ");
int x=e.getX();
int y=e.getY();
System.out.println("at ("+x+","+y+" )");
}
}
public class MouseListenerTest1 extends JFrame{
public static void main(String[] args){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frm=new JFrame();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.addMouseListener(new MouseClickListener());
frm.setSize(200, 200);
frm.setVisible(true);
}
}
mouseClicked
should start with small m. mouseClicked
应该从小m开始。
This is because MouseAdapter
holds an empty implementation of all the interface methods [ mouseClicked
included], and if you don't overload your desired ones with the correct name, you won't even get an error. 这是因为
MouseAdapter
保存了所有接口方法[包含mouseClicked
]的空实现,如果你没有用正确的名称重载你想要的接口方法,你甚至不会收到错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.