以前的答案无法正常使用。 在我的程序中,我想在单击和双击上调用不同的功能,如何识别是单击鼠标还是双击鼠标。如果我使用getClickCount()属性,那么每次双击它也会调用单击fun()。我正在使用部分工作的逻辑。请更正代码。 time1,time2,diff和isdbclicked是全局定义的。
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();
}
}
}
});