0

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

sajad
  • 2,094
  • 11
  • 32
  • 52

1 Answers1

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

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Thank you for replying; but I have question: finally after making jar file and JNLP file; When I want to set tag in html file; which of this files should be as CODE property? Also is it necessary to make an executable file that contains main method? – sajad May 13 '12 at 07:59
  • Sounds like a good question for your next question. Is this question answered? – Andrew Thompson May 13 '12 at 22:39