user2497963
user2497963

Reputation: 43

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);
    }
   }

Upvotes: 0

Views: 306

Answers (1)

moonwave99
moonwave99

Reputation: 22810

mouseClicked should start with small 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.

Upvotes: 2

Related Questions