• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I implement mouse double-click? - Urgent please..  RSS feed

 
Bala Mohan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What do I do if I want to listen to both the single-click and double-click events.
Here is what I did:
new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2)
System.out.println ("Double-click..");
else if(e.getClickCount() == 1) {
System.out.println ("Single-click..");
}
}
The problem is:
When I double-click, both the single-click double-click events are fired. How do I differentiate between them and do something accordingly?
Any help is appriciated..
Thanks,
Bala.
 
Satheesh Thekku Veethil
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bala
The usual way for recognizing double click is with a time interval delay between the single clicks.
So when u hit the first click, the time if registered. Now when u hit the second click u register the time again and compare it with the previous time. If the time difference is within an acceptable range defined, then it can be taken as a double click. Else they exist as two independent clicks.
Hope this helps!!
Sat
 
Richard Teston
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bala
Why dont u evaluate the getClickCount method inside mouseReleased(MouseEvent e)method.
 
Bala Mohan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satheesh & Richard,
Thank you for your replies.
Satheesh, I think your solution will not solve the problem. How do I recognize a single click? ie., when a single click happens, how do I know if it is really a single click or the first click of the double-click? I wouldn't have a second reading at that time. On the other hand, if I wait for the second click to happen, it might never happen if it is really a single click and the user never clicks again. Please correct me if I am wrong.
Richard, I never used mouseRelease () event. Would it generate two events for a double-click? If it does, I will still have the same problem as the mouseClicked() event. If not, my problem is solved! I need to try this out tomorrow.
Thanks,
Murali.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!