要做你在问什么,首先你需要关闭当前阶段。要做到这一点,你需要通过场景(第一个或你想关闭的场景)作为参数或访问场景的任何元素。
,如果你想通过场景参数,你可以通过使用
private void openNewStage(Scene curScene) throws IOException{
Stage stage1 = (Stage) curScene.getWindow();
stage1.close();
Stage stage2 = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("/application/fxml2.fxml"));
Scene scene = new Scene(root,300,300);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
stage2.setScene(scene);
stage2.setTitle("Seceond stage");
stage2.show();
}
如果你想通过访问的第一个场景中的任何元素做...说你有一个名为在Button1的按钮第一FXML文件,那么你可以通过
Stage stage1 = (Stage) button1.getScene().getWindow(); stage1.close();
获得阶段那么,什么是你的具体的编码问题?提供您的尝试,我们可以帮助您解决它。 – MinistryofChaps
关闭前一个阶段的问题到底是什么?您可以在创建它时保留对它的引用,然后在需要关闭它时调用stage.hide(),对吧?! – tomorrow
去检查代码[这里](https://github.com/sedj601/SimpleLoginFx)l – Sedrick