0

Is there a way to take the time in seconds or in milliseconds, between the clicked of the mouse button and the release of this one.

I used this feature, but does not right for me

public void mouseClicked (MouseEvent me) {
   long time=me.getWhen();
  // other stuff
}

some help?

OiRc
  • 1,602
  • 4
  • 21
  • 60
  • Possible duplicate http://stackoverflow.com/questions/1360818/javascript-how-to-measure-the-milliseconds-between-mousedown-and-mouseup – MutantMahesh Apr 26 '14 at 12:02

1 Answers1

1

It didn't work for you because getWhen() returns the time in miliseconds of when that event occured, not the time the event lasted. This code works for me:

long mousePressed;
long mouseReleased;
long mousePressTime;

@Override
public void mousePressed(java.awt.event.MouseEvent e) {
    mousePressed = e.getWhen();
}

@Override
public void mouseReleased(java.awt.event.MouseEvent e) {
    mouseReleased = e.getWhen();

    mousePressTime = mouseReleased - mousePressed;

    System.out.println("PRESS TIME "+mousePressTime);
}
flotothemoon
  • 1,882
  • 2
  • 20
  • 37
  • +1, thanks you so much,i 've tried several type of implementations,this is much fine. – OiRc Apr 26 '14 at 14:13