开发者

Simple Java Applet not loading in FireFox / Safari on MacOS

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>
<开发者_如何学Python/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!


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

What's wrong with my object tag to embed a Java Applet?


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


Remove the line

package SimpleApplet;

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜