简体   繁体   中英

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. My Jpanel form is in another java file called MyForm.java. my JavaApplet class code is:

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>
<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? Is it necessary to put all of my code in single file?

thank you

  1. Add MyForm to a frame instead of the applet. (You might create a frame in a main method and add it there.)
  2. Put those classes in a Jar.
  3. Make a (JNLP) launch file for it.
  4. Launch the Jar from a link using Java Web Start .

In answer to your specific questions.

now can I put both .class files (MyForm.clsss & JavaApplet.cleass) in htmls file?

If the loose class files are both in the same directory (and package), they should be found. Safer though, to use a single Jar.

Is it necessary to put all of my code in single file?

Java source code file? No - definitely not. Classes? Recommend 1 Jar.

If using a Jar, you'd need an archive attribute in the applet element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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