Previously answers are not working properly. In my program i want to call different functions on single and double click, how to identify if it is single mouse click or double mouse click. If i use getClickCount() property then on every double click it also call single click fun(). i'm using a logic which is working partially. please correct the code. time1, time2 , diff and isdbclicked are defined globally.
pane.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
if(event.getEventType().equals(MouseEvent.MOUSE_CLICKED) &&
!event.getEventType().equals(MouseEvent.MOUSE_DRAGGED)) {
if(time1 != 0)
time2 = System.currentTimeMillis();
if(time1 == 0)
time1 = System.currentTimeMillis();
if(time1 != 0 && time2 !=0)
diff = time2 - time1;
if(diff<=300 && diff > 0) {
isdbclicked = true;
time1 = 0;
time2 = 0;
diff = 0;
}
if(diff>1000) {
isdbclicked = false;
time1 = 0;
time2 = 0;
diff = 0;
}
}
if(isdbclicked == true) {
fun1();
} else {
fun2();
}
}
}
});