0

有没有办法找出 Javafx2 应用程序是如何启动的?

IE 是通过网络启动链接启动的,还是通过桌面快捷方式启动的?

我需要知道应用程序是从 Web 启动还是从桌面图标启动的原因是,有一些通过 JNLP 传递的参数,应用程序在从桌面图标启动时不使用这些参数,并且没有其他方法(我我知道)应用程序会知道这些参数是否未传递。

任何指针都会有所帮助。

4

2 回答 2

0

AFAIK,没有好的方法,你需要使用运行模式的副作用。

您可以选择使用下一个:

  1. 小程序总是有 WebContext
  2. Applet/JNLP 总是有 SecurityManager
  3. 桌面运行通常没有 SecurityManager(不是完全可靠),也从来没有 WebContext

见下一个代码:

    Pane root = new VBox(5);

    boolean gotSecurityManager = System.getSecurityManager() != null;
    boolean gotWebContext = getHostServices().getWebContext() != null;

    root.getChildren().addAll(
            new Label("desktop = " + (!gotSecurityManager && !gotWebContext)),
            new Label("jnlp = " + (gotSecurityManager && !gotWebContext)),
            new Label("applet = " + gotWebContext)
            );

    Scene scene = new Scene(root, 500, 250);

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();

另一个选项是我可以查明 java 程序是使用 java 还是 javaw 启动的吗

于 2013-07-09T07:50:23.510 回答
0

(我)..它不会桌面图标一次(第一次)启动?

对,那是正确的。

好的。这是可行的。

在代码中,使用PersistenceServiceJNLP API 检查键/值(例如has-run-once/ true)。如果存在,请使用 JNLP 中定义的属性并设置值。

这是一个小演示。的PersistenceService

于 2013-07-10T14:20:47.630 回答