Migrating Java Applet to Java WebStart (JNLP)

半世苍凉 提交于 2019-12-06 13:39:20

问题


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:

But let's start:

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.

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

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


回答1:


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

Note: the EventQueue.

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.



来源:https://stackoverflow.com/questions/47824650/migrating-java-applet-to-java-webstart-jnlp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!