Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic