如何在JavaFX独立应用程序中将启动画面创建为预加载器? [英] How to create splash screen as a Preloader in JavaFX standalone application?

查看:1128
本文介绍了如何在JavaFX独立应用程序中将启动画面创建为预加载器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a Preloader (based on the following tutorial) that should display a splash screen for the main application.

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

9.3.4 Using a Preloader to Display the Application Initialization Progress 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)中运行主应用程序时都运行预加载器。

I'd like to run preloader each time I run the main application in my IDE (IntelliJ IDEA).

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

I also followed the packaging rules for preloaders in IntelliJ: https://www.jetbrains.com/idea/help/applications-with-a-preloader-project-organization-and-packaging.html

当我运行主应用程序时,预加载器无法启动,所以我想我错过了一些东西。我是Preloaders的新手,我不明白将主应用程序与独立应用程序中的预加载器连接的机制是什么。

When I run the main application the preloader doesn't start, so I suppose I'm missing something. I'm new to Preloaders and I don't understand what is the mechanism to connect the main app with the preloader in standalone application.

推荐答案

您可以像这样使用 LauncherImpl 运行。 。 。

You can run using LauncherImpl like this . . .

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

MyApplication 会是这样的。 。 。

And the class MyApplication would be like this . . .

public class MyApplication extends Application {

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

这篇关于如何在JavaFX独立应用程序中将启动画面创建为预加载器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆