小编B Y*_*Y E的帖子

如何在控制器类的javafx应用程序中交换屏幕?

嘿,我在网上搜索了一段时间,但我找不到解决以下问题的方法:

在javafx中你有3个基本文件; controller-class,fxml文件和应用程序类.现在我想在控制器中做出反应点击按钮(效果非常好)并更改该点击的屏幕(你通常使用stage.setScreen()),但我没有参考舞台(你可以在应用程序类中找到).

应用程序示例:

public class JavaFXApplication4 extends Application {

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();
}

/**
 * The main() method is ignored in correctly deployed JavaFX application.
 * main() serves only as fallback in case the application can not be
 * launched through deployment artifacts, e.g., in IDEs with limited FX
 * support. NetBeans ignores main().
 *
 * @param args the command line arguments
 */ …
Run Code Online (Sandbox Code Playgroud)

javafx javafx-2

19
推荐指数
2
解决办法
3万
查看次数

标签 统计

javafx ×1

javafx-2 ×1