将 Java Applet 迁移到 Java WebStart (JNLP) [英] Migrating Java Applet to Java WebStart (JNLP)

查看:37
本文介绍了将 Java Applet 迁移到 Java WebStart (JNLP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将通过 JNLP 迁移 Java Applet 作为 Java Web Start 应用程序启动并遇到一些麻烦/误解...
我拥有的资源之一是:6 将 Java 小程序迁移到 Java Web Start 和 JNLP:

I'm going to migrate a Java Applet to be started via JNLP as a Java Web Start Application and run into some troubles/missunderstandings ...
One of the resources I've got is this: 6 Migrating Java Applets to Java Web Start and JNLP:

但让我们开始吧:

目前该应用程序是一个小程序 (JApplet),过去是通过将小程序标记嵌入到 HTML 中来启动的.

Currently the application is an applet (JApplet) and was started in past by embedding into an HTML with the applet tag referring to a JNLP.

现在由于所有浏览器都不再支持小程序,我应该将它作为 Java Web Start 运行.

Now since applet support was dropped by all browsers, I should run it as Java Web Start.

由于无法加载资源(JAR 文件),因此仅调用相同的 JNLP 失败.
这是通过向 JNLP 文件添加代码库属性来修复的第一步.

Simply calling same JNLP failed as the resources (JAR files) couldn't be loaded.
This was as a first step fixed by adding an code base attribute to the JNLP file.

Applet 在浏览器之外启动.

Applet is starting outside of the browser.

但现在困难的部分......我应该/想要摆脱任何小程序依赖.

But now the hard part ... I should/would like to get rid of any applet dependency.

但是如何?
什么是正确的方法?
该指南并没有真正说明,因此我有一些问题:

But how?
What is the right approach for that?
The guide doesn't really tell, and therefore I have some questions:

  1. 例如:如何替换 applet.getAppletContext() 的用法及其相关用法?
  2. 指南说我应该在我的main"applet 类中放置一个静态 main.但是我该怎么做呢?
  1. e.g.: How do I replace the usage of the applet.getAppletContext() and related usage of it?
  2. The guide says I should place a static main in my "main" applet class. But How should I do this?

我试过 &以不同的方式启动小程序,但之后我的小程序不再启动.

I tried & to start the applet in different ways, but after that my applet was not starting any more.

我该如何真正替换它?
应用程序的正确包装器应该是什么而不是小程序?
如何开始?

How do I really replace it?
What should be the right wrapper for an application instead of applet?
How to start it?

是否有更详细的指南/示例/教程可以跟随一个真实的例子?

Is there maybe a more elaborate guide/sample/tutorial to follow with a real example?

推荐答案

应用程序的替代容器可能是 JFrame.
迁移路径是将实际的 UI 代码重构(移动)到 JPanel 中.可以将其放入 JApplet 或将 Java WebStart 应用程序放入 JFrame.(在此期间,您可以拥有一个混合应用程序).

An alternative containment for you application could be a JFrame.
A migration path would be refactoring (moving) the actuall UI Code into a JPanel. That one can be placed into the JApplet or for an Java WebStart application into a JFrame. (during that time you could have a hybrid application).

<!-- main in MyApplication -->
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                JFrame frame = new JFrame();
                frame.setTitle("MyApplication via JWS");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                // add here the real UI to the frame: setUpGUI(frame);
                frame.pack();
                frame.setVisible(true);
            }
        });
    }

<!-- Init() in MyApplication extends JApplet -->

    @Override
    public void init() {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                // add here the real UI to the applet: setUpGUI(MyApplication.this);
            }
        });
    }

注意:EventQueue.

Note: the EventQueue.

根据问题1:
必须以不同的方式替换某些 Applet 规范.
在此处查找基础知识:https://docs.oracle.com/javase/9​​/deploy/jnlp-api-examples.htm
例如:对于 AppletContext,有 BasicService 作为某种替代品.

According Question 1:
Some of the Applet specifica have to be replaced be different ways.
Find the basics here: https://docs.oracle.com/javase/9/deploy/jnlp-api-examples.htm
e.g.: for AppletContext there is the BasicService as some kind of replacement.

这篇关于将 Java Applet 迁移到 Java WebStart (JNLP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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