How to embed a JApplet in HTML

Hi all,

When i use the <applet> tag in my browser for viewing a JApplet , I get an error saying class not found.Some of my friends say that the browsers do not support swing classes.IS there a way by which I can view my swing Applet in a browser(Netscape).

Thanks in advance
Who is Participating?
sgomsConnect With a Mentor Commented:
'cos ur using Swing u need to use Java plug-in to invoke the applet.
                for this u need to use <embed> & <object> tags.

                /**Swing applet on the browser**/

                1. The best solution is to use a plug-in.
                   The plug-in is bundled with jdk1.2.x
                else its available for download at,

                Trigger the plug-in
                to trigger the plug-in you need to include <OBJECT> & <EMBED> tags in your html file.
                Normally your HTML will contain,
                <APPLET  CODE = "myapplet.class" WIDTH = 300 HEIGHT = 300 > 
                The HTML file shud look like,
                <!-- CONVERTER VERSION 1.0 -->
                <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
                WIDTH = 300 HEIGHT =
                300  codebase=",2,0,0">
                <PARAM NAME = CODE VALUE = "myapplet.class" > 
                <PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
                <EMBED type="application/x-java-applet;version=1.2" java_CODE = "myapplet.class" WIDTH = 300
                HEIGHT =
                300   pluginspage=""><NOEMBED></COMMENT>

                <APPLET  CODE = "myapplet.class" WIDTH = 300 HEIGHT = 300 > 

                  This is done using the HTML convertor available for download at,

                2. Another option is to include the swingall.jar file into the browsers's classpath.
                3. Else bundle all the swing classes into your archive file & just state
                  <APPLET CODE=myApplet ARCHIVE=myJar.jar WIDTH=300 HEIGHT=300>
                where myJar contains all the swing classes used by myApplet
                This will make the download time of the jar file much slower 'cos the jar file size will be pretty high.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.