如何在JavaFX独立应用程序中将启动画面创建为Preloader?


问题内容

我创建了一个预加载器(基于以下教程),该预加载器应显示主应用程序的初始屏幕。

9.3.4使用预加载器显示应用程序初始化进度 http://docs.oracle.com/javafx/2/deployment/preloaders.htm

public class SplashScreenLoader extends Preloader {

    private Stage splashScreen;

    @Override
    public void start(Stage stage) throws Exception {
        splashScreen = stage;
        splashScreen.setScene(createScene());
        splashScreen.show();
    }

    public Scene createScene() {
        StackPane root = new StackPane();
        Scene scene = new Scene(root, 300, 200);
        return scene;
    }

    @Override
    public void handleApplicationNotification(PreloaderNotification notification) {
        if (notification instanceof StateChangeNotification) {
            splashScreen.hide();
        }
    }

}

每当我在IDE(IntelliJ IDEA)中运行主应用程序时,我都希望运行预加载器。

我还遵循了IntelliJ中预加载器的打包规则:https : //www.jetbrains.com/idea/help/applications-with-a-preloader-project-organization-and-packaging.html

当我运行主应用程序时,预加载器无法启动,因此我想我丢失了一些东西。我是Preloader的新手,我不了解在独立应用程序中将主应用程序与preloader连接的机制是什么。


问题答案:

您可以这样运行LauncherImpl。。。

public class Main {
   public static void main(String[] args) {
      LauncherImpl.launchApplication(MyApplication.class, SplashScreenLoader.class, args);
   }
}

上课MyApplication就是这样。。。

public class MyApplication extends Application {

    @Override
    public void start(Stage primaryStage) {
        ....
        primaryStage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}