2

I am creating javafx application and i want to put screen saver functionality to my application.

If user become inactive for a period of time ( like 1 min ) and did not do any mouse event , i want to add another pane with image on top of it.

when user generates mouse click, screensaver screen should be removed and previous screen should be visible.

Any one can guide me how to do it ?

I know it can be done by generating a new thread but every time a mouse event occurs , i cant add new thread everytime.

public void start(Stage primaryStage) throws Exception{

    Parent root = FXMLLoader.load(getClass().getResource("/fxmls/Main.fxml"));
    Scene scene = new Scene(root,800,480);
    scene.addEventFilter(MouseEvent.MOUSE_RELEASED, (EventHandler<MouseEvent>) event -> {
        EventTarget comp = event.getTarget();

        System.out.println("Event Occured :- " + comp.toString());
    });
    primaryStage.setScene(scene);
    primaryStage.setTitle("Test");
    primaryStage.show();


}

this is i have done so far, i put listener to every mouse click occurred on scene.

  • 3
    Possible duplicate of [Auto close JavaFX application due to innactivity](https://stackoverflow.com/questions/47590919/auto-close-javafx-application-due-to-innactivity) – Zephyr Aug 17 '19 at 13:10
  • See fabian's answer on the question linked above. I think it will work perfectly for your case. – Zephyr Aug 17 '19 at 13:11
  • Why do you want to do that anyway? Isn't the responsibility of the OS? I cannot remember having ever seen an application with a screen saver which would in fact not actually save anything. – mipa Aug 17 '19 at 17:26
  • I am developing app for raspberry pi using javafx that why i need to add screen savor. Thank Zephyr, exactly what i was looking for, i will add modified code for answer for others. – Mehul Changani Aug 19 '19 at 05:00

0 Answers0