user569322
user569322

Reputation:

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'.

Upvotes: 3

Views: 12537

Answers (3)

saygley
saygley

Reputation: 450

Just an up-to-date answer for people that searched Google like me (for many things have changed against Java Web Start and Java Applets).

Below cases might be a reason your Java applet web page is not visible:

Chrome no longer supports NPAPI (technology required for Java applets)

The Java plug-in for web browsers relies on the cross platform plugin architecture NPAPI, which has been supported by all major web browsers for over a decade. Google's Chrome version 45 (scheduled for release in September 2015) drops support for NPAPI, impacting plugins for Silverlight, Java, Facebook Video and other similar NPAPI based plugins. https://www.java.com/en/download/faq/chrome.xml

Firefox limits NPAPI support (technology required for Java applets)

The 64-bit version of Firefox does not support NPAPI plug-ins, including Java. Beginning with Firefox 52 (released March 2017), plug-in support is limited to Adobe Flash, and drops support for NPAPI, impacting plugins for Java, Silverlight, and other similar NPAPI based plugins. https://java.com/en/download/help/firefox_java.xml

It looks like Internet Explorer is the best bet as of now.

Upvotes: 0

Deco
Deco

Reputation: 3321

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.

Upvotes: 5

Umer Hayat
Umer Hayat

Reputation: 2001

As mentioned earlier, it is not recommended to use applet tag. If you are sure that end user browsers will have the JavaScript enabled, you can use this simple way to deploy your applet:

<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {codebase:'http://java.sun.com/products/plugin/1.5.0/demos/jfc/Java2D',
                      code:'java2d.Java2DemoApplet.class',
                      archive:'Java2Demo.jar',
                      width:710, height:540} ;
    var parameters = {fontSize:16} ;
    var version = '1.6' ;
    deployJava.runApplet(attributes, parameters, version);
</script>

The above code will launch the Java 2D applet on JRE version 1.6.0 or higher with one parameter (fontSize).

Upvotes: 2

Related Questions