Question : MouseListener mouseClick single/double click

The mouseClicked() method below looks for double clicks and single clicks. The problem is that on a double click, it processes the single click and then the double. How do I get it process only the double?
1:
2:
3:
4:
5:
6:
7:
public void mouseClicked(MouseEvent event) {
	if (event.getClickCount() == 2) {
		System.out.println ("dbl-clk");
	}	
        else if (event.getClickCount() == 1) {
		System.out.println ("clk");
        }

Answer : MouseListener mouseClick single/double click

This si the way Java is, an anoying problem. The only way around it that I have found is to initiate a timer for how long you think the second click should take after the first one (0.5-1 second I think is ok, but have a play with it)

See the code example below, I grabbed it from http://forums.sun.com/thread.jspa?forumID=257&threadID=413348

let me know if you need more help, Regards
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
component.addMouseListener( new MouseAdapter() {
			final Timer timer = new Timer( 300,new ActionListener(){
				 public void actionPerformed(ActionEvent e) { 
					System.out.println("single");
					timer.stop(); 
				}
			});
			public void mouseClicked (MouseEvent e){
				if(timer.isRunning()) {
					timer.stop();
					System.out.println("double"); 
				}else {
					timer.restart();
				}
			}
	});
Random Solutions  
 
programming4us programming4us