我在这里遵循一个教程,我绝对做了同样的事情,但是当我点击鼠标按钮时没有任何反应。我试图调试,但我不知道该怎么做。
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);
}
}