I have a window with a button. Clicking this button opens a modal window. Now, I want to close this second window by clicking a button, but I can't figure out how.
public class StartMenu extends Application {
@Override
public void start(Stage primaryStage) {
final Button b = new Button("Go");
b.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
AnotherWindow aw = new AnotherWindow ();
aw.start(stage);
}
});
((Group) scene.getRoot()).getChildren().add(b);
primaryStage.setScene(scene);
primaryStage.show();
}}
public class AnotherWindow extends Application {
@Override
public void start(Stage primaryStage) {
final Button b = new Button("Back");
b.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
//Code to close window
}
});
((Group) scene.getRoot()).getChildren().add(b);
primaryStage.setScene(scene);
primaryStage.show();
}}