Hello,
I'm curious why I got the "right" BUT "wrong"number of result when I click the mouse.
I supposed to print on the console mouseClicked
once everytimes the mouse is clicked. However I got many of them printed out everytimes I clicked the mouse ...sometimes 5 e.g.
mouseClicked
mouseClicked
mouseClicked
mouseClicked
mouseClicked
Instead of just
mouseClicked
Why?
public class GUI extends JFrame implements MouseListener, ActionListener {
.....
public GUI {
GridBagLayout m = new GridBagLayout();
Container c = getContentPane();
c.setLayout (m);
GridBagConstraints con = new GridBagConstraints();
....
JPanel pDraw = new JPanel(new GridLayout(ROWS,COLS,2,2));
con = new GridBagConstraints();
...
m.setConstraints(pDraw, con);
pDraw.addMouseListener(this);
pack();
setVisible(true);
}
public void mouseClicked(MouseEvent arg0) {
System.out.println("mouseClicked");
}
}