Skip to content Skip to sidebar Skip to footer

JApplet Fails To Run In HTML Page

I have created a JApplet using the JUNG library in Netbeans that compiles and runs normally. However, when I try to create an html file that runs the applet, only a grey pane appea

Solution 1:

You mention the JUNG library, it relies on the two third party libraries, Collections-Generic & Cern Colt Scientific Library 1.2.0. As mentioned by @othman they need to be added to the run-time class-path of the applet (added to the archive attribute of the applet element).

But just so we are clear, make sure the HTML contains more than just the applet element. Something like this:

<html>
<body>
<applet 
    code='MyPackage.View' 
    archive='MyProject.jar,jung.jar,collections.jar,colt-scientific.jar'
    alt='Java is DISABLED in this browser!'
    width='1600'
    height='800'>
This browser does not recognize the applet element! 
</applet>
</body>
</html>

Of course, you'll need to change the names of the last 3 Jars to their real names.


Solution 2:

I'm no Applet expert, since I don't use them, but IIRC you need the init() method to initialize your view. main(...) is not called for an applet.


Solution 3:

First, I am not sure that new lines you added into the html are legal. I mean write <applet and /> without any new lines and spaces.

Second, test that your jar is really available. To do this go to the same URL that you go to retrieve your HTML without HTML but with jar, i.e.

if your HTML URL is: http://somehost/my.html type in browser http://somehost/MyProject.jar and see that you can download the jar.

if this works check the code attribute. Is your package name really MyPackage? Capitalized? Do you know it is not according the naming convention?

Also check java console. Find it somewhere in menus of your browser: it depends in browser. I believe that you will see the reason there in form of exception stack trace.


Solution 4:

you need to reference also the JUG jars in your applet tag :

<

applet code = 'MyPackage.View' 

archive = 'MyProject.jar , jung_xx.jar',

width = 1600, 

height = 800 /
>

in the archive attribute add all jung jars that you have currently in your netbeans project classpath.


Post a Comment for "JApplet Fails To Run In HTML Page"