简体   繁体   English

在JApplet上添加JPanel并编写HTML页面以运行它

[英]adding JPanel On JApplet and writing HTML page to run it

I have a java applet and I want to add a pre-designed Jpanel on my jpanel as a form. 我有一个Java小程序,我想在我的jpanel上添加一个预先设计的Jpanel作为表单。 My Jpanel form is in another java file called MyForm.java. 我的Jpanel表单位于另一个名为MyForm.java的Java文件中。 my JavaApplet class code is: 我的JavaApplet类代码是:

public class JavaApplet extends JApplet{
    @Override
    public void init(){
        Container container = this.getContentPane();
        container.add(new MyForm());
    }
     }

My html code to run this page is as simple: 我运行该页面的html代码很简单:

<HTML>
<HEAD>
<TITLE>The Palindrome Page</TITLE>
</HEAD>
<BODY>
<P>My favorite meat-related palindrome is:
<BR>
<APPLET CODE="JavaApplet.class" WIDTH=600 HEIGHT=100>
A secret if your browser does not support Java!
</APPLET>
</BODY>
</HTML>

now can I put both .class files (MyForm.clsss & JavaApplet.cleass) in htmls file? 现在可以将两个.class文件(MyForm.clsss和JavaApplet.cleass)放入htmls文件吗? Is it necessary to put all of my code in single file? 是否有必要将我的所有代码放在单个文件中?

thank you 谢谢

  1. Add MyForm to a frame instead of the applet. MyForm添加到框架而不是applet。 (You might create a frame in a main method and add it there.) (您可以在main方法中创建一个框架并将其添加到其中。)
  2. Put those classes in a Jar. 将这些课程放在一个Jar中。
  3. Make a (JNLP) launch file for it. 为此创建一个(JNLP)启动文件。
  4. Launch the Jar from a link using Java Web Start . 使用Java Web Start从链接启动Jar。

In answer to your specific questions. 在回答您的特定问题。

now can I put both .class files (MyForm.clsss & JavaApplet.cleass) in htmls file? 现在可以将两个.class文件(MyForm.clsss和JavaApplet.cleass)放入htmls文件吗?

If the loose class files are both in the same directory (and package), they should be found. 如果松散的类文件都在同一目录(和程序包)中,则应找到它们。 Safer though, to use a single Jar. 不过,使用单个Jar更为安全。

Is it necessary to put all of my code in single file? 是否有必要将我的所有代码放在单个文件中?

Java source code file? Java源代码文件? No - definitely not. 不-绝对不是。 Classes? 上课吗 Recommend 1 Jar. 推荐1罐。

If using a Jar, you'd need an archive attribute in the applet element. 如果使用Jar,则在applet元素中需要有archive属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM