How does JavaFX close the pop-up window?

clicking the button in the MainStageController controller will open a new window. How to judge that if this window pops up on the second click, it will not pop up

 @FXML
  private void handleSubmitButtonAction(ActionEvent event) {
    actionTarget.setText("...");

    /**
     * stage
     */
    Stage stage = (Stage) rootGridPane.getScene().getWindow();
    stage.close();

    // stage
    Stage secondStage = new Stage();
    final JmetroStageView view = new JmetroStageView();
    ApplicationContext context = SpringContextUtil.getApplicationContext();
    view.setApplicationContext(context);
    secondStage.setScene(new Scene(view.getView()));
    secondStage.show();
  }
Dec.13,2021
Menu