tags:

views:

414

answers:

4

Hello all,

I'm probably missing something very basic here. I'm trying to get my first applet to run inside a local HTML page in Firefox 3.6 on Mac OS 10.5.8. Here's the applet's code:

package SimpleApplet;

import java.applet.Applet;
import java.awt.*;

public class MyApplet extends Applet {

private static final long serialVersionUID = 1L;

public void init()
{
}

public void stop()
{
}

public void paint(Graphics g)
{
g.drawString("Tweedle-Dee!",20,40);
} 

}

Here's the HTML page:

<html>
<body>
Here's the applet: <br/>
<applet code="MyApplet.class" width="300" height="150">
</applet>
</body>
</html>

Both files (.class and .html) are in the same folder on my local machine. Now when I load the .html file into Firefox, a rectangle with a red X gets displayed. The applet works when started from Eclipse (using JRE 1.5 BTW).

Also, it's not a general problem with my browser, as several pages with applets (e.g. http://java.sun.com/applets/jdk/1.4/demo/applets/Blink/example1.html) work.

This is also difficult to troubleshoot because there is no output at all on the Java console...

Any suggestions are appreciated!

+1  A: 

Try omitting the .class

This in combination with using the object tag I had better results.

<object classid="java:com.something.fullyQualifiedClassName">
            <param name="type" value="application/x-java-applet">
</object>

also see my question and specifically the selected answer, as this is simular to what i had experienced

http://stackoverflow.com/questions/2730183/whats-wrong-with-my-object-tag-to-embed-a-java-applet

predhme
Thanks, but that didn't improve things.
Sleepless
See my edit. I had better results getting things to work using the object tag. That and the applet tag has been deprecated since HTML4.
predhme
OK, thanks for the info, but I tried that, still with the same results.
Sleepless
I'd suggest reading the documentation that is linked in my question's answer. That will most likely point you in the correct tweaks to get it to work.
predhme
A: 

I found the problem. I had to move MyApplet.class into a subfolder called SimpleApplet.

Sleepless
A: 

Remove the line

package SimpleApplet;

And this means you won't need it in a folder called SimpleApplet.

Dean
A: 

I tried both versions, as well as the "embed" tag suggested in the aforementioned documentation. All of them work in appletviewer, none of them work in Firefox. Other applets (such as the Blink example) run in Firefox, so Java is turned on.

Any other ideas?

mundungus