I am developing a JavaFX application where I am using java.util.Timer
to track user mouse movement.
The concept is If the mouse doesn't move for some seconds in the scene then the buttons will be invisible whenever the mouse moves button will appear again. And whenever user put the cursor over a button timer will be stopped.And when exit the button timer will start again.
This is the start timer method
public static void startTimer(){
timer = new Timer();
task = new TimerTask() {
@Override
public void run() {
if(detection>0){
Util_Class.getUi_obj().getLeftbuttongroup().setVisible(false);
Util_Class.getUi_obj().getRightbuttongroup().setVisible(false);
}else{
detection++;
}
}
};
timer.schedule(task, 2000, 2000);
System.out.println("TIMER STARTED");
//startTimer();
}
This is to stop the timer
public static void stopTimer(){
timer.cancel();
System.out.println("TIMER STOPED");
}
public void leftbuttonmovehandler(MouseEvent event){
if(event.getEventType()==MouseEvent.MOUSE_ENTERED){
System.out.println("MOUSE ENTERED");
Main.stopTimer();
}else if(event.getEventType()==MouseEvent.MOUSE_EXITED){
System.out.println("MOUSE EXITED");
Main.start();
}
}
Now my code works fine at first whenever the app starts but when i reload the app the callback functions triggers as expected but the buttons disappear despite the cursor is on the button.
It would be great if someone helps me.