How to record the number of mouse clicks in Java?
A:
Generally speaking, you would attach a mouse click event handler, and whenever your handler gets called, you would increment an integer counter.
Douglas
2010-08-01 21:57:56
+3
A:
Something along the lines of this should do it, Adding the MouseListener on any component you want to listen for clicks on
public class MyFrame extends JFrame implements MouseListener{
/** Number of times the mouse was clicked */
private int clicks = 0;
public MyFrame ()
{
this.addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
//Increment click count
clicks++;
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e) { }
}
Re0sless
2010-08-01 22:01:52