【发布时间】:2019-07-10 16:14:45
【问题描述】:
我问的是节点、场景和父母之间的关系。我实际上正在学习JavaFX,并且很难在同一帧中更改场景。我为此建立了一种方法,但实际上我不知道它是如何工作的。你能帮我弄清楚吗?
我尝试在 Java 参考、youtube 上以及在 google 上搜索关键字“Scenes Parent”,但没有找到任何对我有帮助的东西。
public class SceneCreator {
// launching the new scene based on the .fxml file name passed in the argument as a String variable
// building the scene and setting the value for the instance variable loader
public static void launchScene (String sceneName) throws IOException {
// Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
FXMLLoader loader = new FXMLLoader(Main.class.getResource(sceneName));
Main.setRoot(loader.load());
Scene scene = new Scene(Main.getRoot());
Main.getStage().setScene(scene);
Main.getStage().show();
@FXML
private void sphereClick() throws IOException{
System.out.println("Sphere button clicked");
SceneCreator.launchScene("sphere.fxml");
}
【问题讨论】: