Search code examples
javatomcatappletclasspathjapplet

using applet with several classes


I’m a newbie with applets so please be patient with me.

I have a japplet class that uses a several classes and I want to run it from the browser. I'm using Tomcat to run the applet, I can't find away to link the other classes to the Japplet class.

Where to put the other classes? or any other idea that will help me solve this problem.

my HTML

<html>
<title>Test Applet</title>
<hr>
<applet class="Main.class" width="320" height="120">
</applet>
<hr>
</html>

My applet class:

import javax.swing.JApplet;
import com.getSlide.MainApp;

public class Main extends JApplet {

    public void init() {
        System.out.println("init");
        MainApp main = new MainApp();
    }
}

Solution

  • Where to put the other classes?

    That depends on what package they are in. If they are in the default pack like the Main (as class="Main.class" implies), the same directory.

    OTOH it is better to put the classes into a Jar.

    How can I call the jar from the applet?

    Presuming the Jar is called the.jar..

    <html>
    <title>Test Applet</title>
    <hr>
    <applet code="Main" archive="the.jar" width="320" height="120">
    </applet>
    <hr>
    </html>
    

    Note also that:

    class="Main.class"
    

    Should be:

    code="Main"