我正在按照教程here我絕對做了同樣的事情,但是當我點擊鼠標按鈕時什麼也沒有發生。我試圖調試,但我不知道該怎麼做。鼠標點擊監聽器不會觸發
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);
}
}
爲更好地幫助發佈[SSCCE](http://sscce.org/),短,可運行,可編譯 – mKorbel