0

On my app, there is a primary window and a secondary for some changes. When the user want to close the app (= primary window) i want to ask from the user the confirmation for closing the secondary window of the changes to avoid being lost of changes.

This code is on my main class.

My problem is that i can't check from my main class if the secondary window is open or not.

Notice: The secondary window is being created on my maincontroller class.

Thanks!

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));

        Scene scene = new Scene(root);
        scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
        primaryStage.getIcons().add(new Image("image.png"));
        primaryStage.setTitle("Κάβα ποτών");
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
            event.consume();
            closing();
            }
        });

    }

    public void closing() {
        //if(the secondary window is closed)
              //Platform.exit();
        //else
              //ask confirmation with confirm alert
    }

    public static void main(String[] args) {
        launch(args);
    }  
}
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
  • Welcome to Stack Overflow! Consider accepting the answer below by clicking the checkmark next to it. This will help both @HungryCosmos by giving them more rep and future users searching similar questions by letting them know that this one has an accepted answer. – MMAdams Oct 13 '17 at 12:25

1 Answers1

1

Use isShowing method do determine if SecondaryStage is opened.

To use it, you should assign SecondaryStage to a variable when you create the stage and provide access to it by making it public or providing getters.

And this is how to access controller from your Main class.

Hope it helps.

Bekzh
  • 173
  • 7