MouseAdapter Not working

0 pratt 15 · August 1, 2014
Hey guys, i was making the program to count no. of clicks and to show which button you have pressed during click, but it is not working ....plz correct it 


package pratt;

import java.awt.*;
import java.awt.event.*;

import javax.swing.event.*;
import javax.swing.*;

public class project2 extends JFrame {
private JPanel panel;
private JLabel label;
private String string;

public project2() {
super("Title");
panel = new JPanel();
panel.setBackground(Color.WHITE);
add(panel, BorderLayout.CENTER);

label = new JLabel("Label");
add(label, BorderLayout.SOUTH);

Handlerclass handler = new Handlerclass();
panel.addMouseListener(handler);

}

public class Handlerclass extends MouseAdapter {

public void mouseCLicked(MouseEvent event){
string=String.format("You clicked %d ",event.getClickCount());
label.setText(string);

if(event.isAltDown())
string=string+ String.format("With center button");

else if(event.isMetaDown())
string=string+ String.format("With right button");

else
string=string+ String.format("With left button");

label.setText(string);



}

}

}

Post a Reply

Replies

Oldest  Newest  Rating
0 pratt 15 · August 1, 2014
sorry but i found my mistake.... i wrote mouseCLicked instead of mouseClicked....lolz:P
+1 pratt 15 · August 1, 2014
Actually even compiler didnt showed any error......after this i think i should be less dependent on eclipse..:D:D... 
thnks Brano....
  • 1

Java / Android Development

126,579 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator