Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

html - Java - Applet simply not displaying?

Okay, so I did a little applet tutorial, and I read that the init() method is required for an applet to run. And it does. At least in my IDE (Eclipse). The Applet Viewer has no problems running my applet, when I try to do the <applet> tag in HTML, nothing displays, but it acts as though something is there (text position is altered by the tag). Here is my applet:

import java.awt.*;
import javax.swing.*;

public class Applet extends JApplet{
    public void init(){
        Label label = new Label("Hello!");
        this.add(label);
    }
}

And this is the code I'm using on my webpage:

<applet code="Applet.class" width=100 height=100></applet>

Even if I remove the width/height parameters, I get the same result (it doesn't display on the page). Yes, the path to the applet is correct and in the same directory. Thank you for your help.

If it helps, this is my DOCTYPE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Finally, after scouring the console, I found this:

Could not read chrome manifest file '/usr/lib/firefox-8.0/extensions
/{972ce4c6-7e08-4474-a285-3208198ce6fd}/chrome.manifest'.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The applet tag is deprecated and the object tag should be used instead. The applet tag is not supported by some browsers which is probably why you cant see the applet, whereas the object tag should work with pretty much all of them these days.

Edit: Provide code example::

<OBJECT codetype="application/java"
        classid="java:Applet.class"
        width="500" height="500">
My first Java applet.
</OBJECT>

See this link and this link for further examples and information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...