如何在 Eclipse 中将 JavaFX Preloader 与独立应用程序一起使用? [英] How to use JavaFX Preloader with stand-alone application in Eclipse?

查看:22
本文介绍了如何在 Eclipse 中将 JavaFX Preloader 与独立应用程序一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 IDE 是 Eclipse,我的项目是一个独立的 JavaFX 应用程序(带有 OSGI 框架的纯 CS 架构).

My IDE is Eclipse and my project is a stand-alone JavaFX application (pure CS architecture with OSGI framework).

如何使用预加载器,从而使预加载器在我的主应用程序之前启动并稍后隐藏?

How to use preloader thus the preloader would be started before my main application and hid later?

我在这里找到了一些代码:

I found some code here:

http://docs.oracle.com/javafx/2/deployment/preloaders.htm#BABGGDJG

但我仍然不知道如何在 OSGI 框架中使用我的启动应用程序部署预加载器.

But I still don't know how to deploy the preloader with my startup application in an OSGI framework.

我在下面给出了我的启动应用程序的一些代码:

I give some code of my startup application below:

public class MyPrjMain extends Application {
    private static Stage primaryStage;

    public void start(final Stage stage) throws BusinessException {
        primaryStage = stage;
    
        init(primaryStage);
    
        primaryStage.show();
    }
}

推荐答案

这是一个长答案,不耐烦的快速答案是下载这个 示例代码,用于显示密集启动任务的启动页面,看看它是否适合您的情况.

This is a long answer, the quick answer for the impatient is to download this sample code for displaying a splash page for an intensive startup task and see if it is adaptable to your situation.

我的回答提供了关于 Preloader 样式的一般信息JavaFX 中的功能.您的问题特别提到了 Preloader 在 Eclipse 和 OSGI 环境中的使用,但我不会直接解决这种情况,因为我不使用这些技术.希望一般信息仍然适用于您的场景.

My answer provides general information about Preloader style functionality in JavaFX. Your question specifically mentions Preloader usage in an Eclipse and OSGI environment, but I won't directly address that scenario as I don't use those technologies. Hopefully the general information is still applicable to your scenario.

1.Java 原生支持在 Java 启动时显示启动页面.

优缺点:

+ 让独立应用程序显示启动图像的最简单方法.

+ The simplest way to get your standalone application to show a splash image.

+ 可以很快显示=> 它是 VM 进程的参数输入,因此(大概)它甚至可以在 VM 本身完全初始化之前显示.

+ Can be displayed very quickly => it's an argument input to the VM process, so (presumably) it can be displayed even before the VM itself has fully initialized.

- 功能有限=> 只允许显示图像,不允许显示其他预加载器功能,例如报告初始化进度、动画、登录提示等(除非您 利用 AWT API)

- Has limited features => only allows display of an image, not other preloader features such as reporting of initialization progress, animation, login prompts etc (unless you make use of AWT APIs)

- 在 Java 8 之前无法在所有平台上运行(请参阅 issue Mac:无法使用 -splash:JavaFX 2.2 和 JDK 7).

- Won't work on all platforms until Java 8 (see issue Mac: Impossible to use -splash: with JavaFX 2.2 and JDK 7).

2.预加载器可用于独立应用程序.

JavaFX 预加载器教程9.3.4 使用预加载器显示应用程序初始化进度.本教程在 LongInitAppPreloaderLongInitApp 类中提供了可执行示例代码(使用我在本答案中提供的类名,因为教程中的一个名称目前是错误的).

The JavaFX Preloader tutorial has an example in the section 9.3.4 Using a Preloader to Display the Application Initialization Progress. The tutorial provides executable sample code in the LongInitAppPreloader and LongInitApp classes (use the class names I provide in this answer as one name in the tutorial is currently wrong).

示例独立应用程序的初始化时间很长,自定义Preloader 可提供有关初始化进度的反馈.该示例通过 Task 模拟长初始化Thread.sleep 调用,但真正的应用程序会执行一些操作,例如建立网络连接、检索和解析网络数据以及设置初始应用程序 场景.

The sample standalone application has a long initialization time and a custom Preloader provides feedback on the progress of the initialization. The sample simulates the long initialization through a Task with a Thread.sleep call, but a real application would be doing something like establishing network connections, retrieving and parsing network data and setting up the initial application Scene.

预加载器并非特定于小程序和 WebStart,而是主要针对这些部署类型.小程序和 WebStart 的初始化过程比独立的应用程序初始化更复杂,因此预加载器文档的大部分内容都专门用于那些更复杂的场景.

Preloaders are not specific to applets and WebStart, but are primarily targeted to those deployment types. The applet and WebStart initialization process is more complex than standalone application initialization, so much of the Preloader documentation is devoted to those more complex scenarios.

3.您不需要将预加载器放在单独的 JAR 中.

您可以将 Preloader 放在与您的 应用程序 类.对于通过网络加载协议(例如 WebStart)动态部署和更新的大型应用程序,放置 Preloader 在一个单独的 JAR 中是有道理的.对于执行基于网络的初始化的独立应用程序,它可能没有太大区别,可以跳过单独的打包步骤以简化构建和部署过程.

You can place the Preloader in the same JAR as your Application class. For large applications dynamically deployed and updated over network loading protocols such as WebStart, placing the Preloader in a seperate JAR makes sense. For standalone applications performing network based initialization, it probably doesn't make much difference and the separate packaging step could be skipped to simplify the build and deployment process.

4.您无需使用预加载器即可实现预加载器风格的功能.

无需子类化即可实现大部分(并非全部)预加载器功能 预加载器.

Much (not all) of the Preloader functionality can be achieved without subclassing Preloader.

您可以:

  1. 在应用程序的 Stage 中创建一个启动start 方法.
  2. 放置初始图像和 ProgressBar在启动阶段.
  3. 有一个背景任务用于冗长的应用程序初始化过程.
  4. 从后台任务向启动阶段报告初始化进度.
  5. 在初始化完成时,要么:
    • a.用新创建的应用程序阶段替换启动阶段或
    • b.将启动阶段的场景内容替换为应用程序的新场景.
  1. Create a startup Stage in your application's start method.
  2. Place a splash image and ProgressBar in the startup stage.
  3. Have a background task for lengthy application initialization processes.
  4. Report initialization progress back to your startup stage from your background task.
  5. On initialization completion, either:
    • a. Replace the startup stage with a newly created application stage OR
    • b. Replace the contents of the scene in the startup stage with a new scene for your application.

5b 可能是首选,这样您就不需要创建多个窗口.

5b is probably preferred so that you don't need to create multiple windows.

有关此策略的示例,请参阅我对以下问题的回答:

For examples of this strategy, see my answers to the following questions:

在不使用Preloader的情况下在JavaFX中显示进度监控闪屏的相关示例代码是:

The related sample code for displaying Progress Monitoring splash screens in JavaFX without using a Preloader is:

上面的代码可以重构为使用 Preloader 子类来代替,在这种情况下,有一个明确定义的框架来通知应用程序初始化事件,并且可以使用更灵活的部署模型(例如单独 jar 中的预加载器).然而,使用 Preloader 可能有点复杂.对于某些实现,可能不值得花时间了解 Preloader 框架.

The above code could be refactored to use a Preloader subclass instead, in which case there is a well defined framework for notification of application initialization events and more flexible deployment models (e.g. preloader in seperate jar) are available. However use of a Preloader may be a little complicated. For some implementations, it may not be worth the time to understand the Preloader framework.

5.WebStart 应用程序具有对 Splash 图像的 JNLP 支持

(这点无关紧要,只是为了完整性而包括在内).

(this point is pretty irrelevant and just included for completeness).

我相信 webstart 应用程序可以在他们的 jnlp 文件中有一个标志来显示webstart 应用程序启动时的启动图像,但我从来没有能够让该标志在 JavaFX 2 应用程序中工作,只能在 Swing 应用程序中工作,即使那样它也不是那么可靠,因为它只会第二次显示应用程序已启动.

I believe that webstart applications can have a flag in their jnlp file to show the startup image as the webstart application launches, but I've never been able to get that flag to work in a JavaFX 2 application, only in a Swing application and even then it wasn't all that reliable as it would only display the second time the application was launched.

这篇关于如何在 Eclipse 中将 JavaFX Preloader 与独立应用程序一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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