Using the System.currentTimeMillis( )
method how can I detect if at least 200ms have passed in between mouse clicks? I have the following method that passes in a boolean value that tells you if the mouse button is currently pressed down or not. This method is called every 20ms.
public void update(boolean mouseDown)
I thought about using a series of if statements but I just can't get it to work.
if(mouseDown)
{
click = true;
waitTime = System.currentTimeMillis();
}
if(click && (!mouseDown) && (waitTime-System.currentTimMillis()) <= 200)
{
//You got a Double Click
}
else if(click && (!mouseDown))
{
//You got a Single Click
}
The problem is since the method is called every 20ms it always registers it as a double click. It always enters the first if statement and resets the value so I never end up with a time that is greater then 200ms. Any idea how I can fix this?