Converting a JFrame to a JApplet

こ雲淡風輕ζ 提交于 2019-11-26 22:09:22

问题


I have a JFrame application working nicely. However now I'd like to run it on the web as an Applet. This is what I've done:

import MyPackage.*;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class MyName extends JApplet
{

     public void init() {
        setSize(600,450);
        new MyName()
     }

    public MyName() {
        JShellFrame frame = new JShellFrame(true, null, null);
        frame.setVisible(true);
    }

}

How can I make an html file to run this applet? Also, I have an external jar file that the applet will need. Does the applet not need a main method?


回答1:


Check out Getting Started With Applets. It covers relevant methods and life cycle. It mentions main method as well:

Unlike Java applications, applets do not need to implement a main method.

Deployment section covers HTML file details. For dependency jars you can specify more than one jar in archive attribute of applet tag.




回答2:


However now I'd like to run it on the web..

Then drop this nonsense and launch the frame from a link using Java Web Start. I say 'nonsense' for two reasons.

  1. JWS has existed since Java 1.2, & has been discussed in these forums several times in the last few days in regard to applets. Seems you are not doing much research.
  2. Of the 'gargantuan' 2 lines of applet code code shown above, one of them is ill-advised and the other is either pointless or would risk creating a stack overflow error (could not be bothered trying it to find out which).



回答3:


here's some html that will work:

<applet archive = "appName.jar" width = 900 height = 506 code = "main.class"/>

You can change the width and height according to the size your app needs. Also make sure to put the url as a path to the jar.



来源:https://stackoverflow.com/questions/10059885/converting-a-jframe-to-a-japplet

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