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

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

问题描述

我要将Java Applet迁移到JNLP作为Java Web Start应用程序启动并遇到一些麻烦/误解...

我得到的资源之一就是这个: 6将Java Applet迁移到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 ),并且过去通过嵌入到带有引用JNLP的applet标记的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.

现在,由于所有浏览器都删除了applet支持,我应该将其作为Java Web Start运行。

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

简单地调用相同的JNLP作为资源失败(JAR文件)无法加载。

这是通过向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.

但现在困难的部分......我应该/会喜欢摆脱任何applet依赖。

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. 指南说我应该在我的主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?

我试过&以不同的方式启动applet,但之后我的applet不再启动了。

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

我如何真正替换它?

什么应该是应用程序而不是applet的正确包装?

如何开始吧?

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