0

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();
            }
        }
    }
});
  • This is not a duplicate question because the referenced answer does not handle the specific case which is asked for here. I would have a solution for this problem if I could post an answer here. – mipa Mar 26 '16 at 15:02
  • All those previous answers are not applicable for my program. If you have an answer please share. – Vikram Bhardwaj Mar 26 '16 at 20:31

0 Answers0