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

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

问题描述

我的IDE是eclipse,我的项目是一个独立的javaFX应用程序(纯CS架构与OSGI框架)。



如何使用Preloader,因此预加载程序将在我的主要应用程序之前启动并隐藏?



我在
中找到一些代码 http://docs.oracle.com/javafx/2/deployment/preloaders.htm#BABGGDJG



但是我仍然不知道如何在OSGI框架中使用我的启动应用程序来部署Preloader。
我给我下面的启动应用程序的一些代码:

  public class MyPrjMain extends Application {
private static舞台一级

public void start(final Stage stage)throws BusinessException {
primaryStage = stage;

init(primaryStage);

primaryStage.show();
}
}

非常感谢大家。

解决方案

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






我的回答提供了有关预加载器样式功能在JavaFX。您的问题在Eclipse和OSGI环境中具体提到 Preloader 的用法,但是我不会直接解决这种情况,因为我不使用这些技术。希望一般信息仍然适用于您的方案。



1。 Java在Java启动时具有显示启动页面的本地支持。




  • 这可以使用 -splash:< image> VM切换



优点和缺点:



+ 获取独立应用程序以显示快速图像的最简单方法。



+ 可以非常快速地显示
=>它是对VM进程的输入参数,所以(可能)即使在VM本身完全初始化之前也可以显示。



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



- 直到Java 8才能在所有平台上运行(请参阅问题 Mac:不可能使用-splash:与JavaFX 2.2和JDK 7 )。



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



JavaFX Preloader教程 9.3.4使用预加载器显示应用程序初始化进度的一节中有一个例子。本教程提供 LongInitAppPreloader LongInitApp 类中的可执行示例代码(使用我在此答案中提供的类名称作为一个



示例独立应用程序具有很长的初始化时间和自定义的预加载器提供有关初始化进度的反馈。该示例通过任务与一个 Thread.sleep 调用,但一个真正的应用程序将会做一些建立网络连接,检索和解析网络数据并设置初始应用程序的方式场景



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



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



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



4。您可以在不使用预加载器的情况下实现预加载器样式功能。



预加载器功能的很多(并非全部)功能可以在不进行子类化的情况下实现 Preloader



您可以:


  1. 创建启动 Stage 在您的应用程序的开始方法。

  2. 放置快速图像,然后将 ProgressBar 启动阶段。

  3. 有一个背景
  4. 从后台任务向初始化阶段报告初始化进度。

  5. 初始化完成后,可以:


    • a。用新创建的应用程序阶段替换启动阶段OR

    • b。在启动阶段将现场的内容替换为应用程序的新场景。


5b可能是首选,因此您不需要创建多个窗口。



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



在不使用 Preloader 的情况下,在JavaFX中显示进度监视启动屏幕的相关示例代码是:





上述代码可以重构使用预加载器在这种情况下,存在用于通知应用程序初始化事件和更灵活的部署模型的良好定义的框架(例如,单独的jar中的预加载器)可用。但是,使用 Preloader 可能有点复杂。对于某些实现,了解 Preloader 框架可能不值得。



5。 WebStart应用程序对Splash Images有JNLP支持



(这一点是非常无关紧要的,仅供参考)。



我相信 webstart应用程序可以在他们的jnlp文件中有一个标志在启动webstart应用程序时显示启动映像,但是我从来没有能够使该标志在JavaFX 2应用程序中工作,只能在Swing应用程序中运行,即使这样也不是可靠的,因为它只会显示第二次申请被推出。


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 in http://docs.oracle.com/javafx/2/deployment/preloaders.htm#BABGGDJG

But I still don't know how to deploy the Preloader with my startup Application in a 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();
    }
}

Thanks very much, everybody.

解决方案

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.


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 has native support for displaying a splash page when Java is started.

  • This works using the -splash:<image> VM switch.

Advantages and disadvantages:

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

+ 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.

- 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)

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

2. Preloaders may be used for standalone applications.

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).

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.

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. You don't need to place a Preloader in a separate 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. You can achieve Preloader style functionality without using a Preloader.

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

You can:

  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 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:

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

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 Apps have JNLP support for Splash Images

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

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天全站免登陆