javaappletjappletappletviewer

Creating a Java Applet to Launch in Browser


I am working on a homework assignment that is requiring me to create a basic applet that runs in a browser. I already know that the applets have been deprecated, so I know that this probably will not work with current browsers.

This is my Java code:

import java.applet.Applet;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JLabel;


public class SimpleJavaApplet extends JApplet{

    public void paint(Graphics g) {
        g.drawString("Hello World!", 80, 80);
        g.drawString("Blah!", 100, 100);
    }

}

This is my HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>A Short Test</title>
</head>
<body>
    <title>Test Applet</title>
    <applet code="SimpleJavaApplet.class" width = "200" height = "50">
    </applet>
    <h1>Test Test Test</h1>
</body>
</html>

What I was hoping would happen is that a browser would launch and it would show up with the HTML, but the only think I have been able to get to run is the AppletViewer. I am wondering if this is even possible anymore and if I should just let my professor know that.

Any ideas will be greatly appreciated.

Edit: Just to make things clearer, I am trying to run this code so it runs through a browser and not just the AppletViewer.


Solution

  • Neither Chrome nor Firefox are no longer supported NPAPI.

    Java and Firefox Browser

    Firefox no longer provides NPAPI support (technology required for Java applets) As of September, 2018, Firefox no longer offers a version which supports NPAPI, the technology required to run Java applets. The Java Plugin for web browsers relies on the cross-platform plugin architecture NPAPI, which had been supported by all major web browsers for over a decade. The 64 bit version of Firefox has never supported NPAPI, and Firefox version 52ESR is the last release to support the technology. It is below the security baseline, and no longer supported.

    Java and Google Chrome Browser

    Chrome no longer supports NPAPI (technology required for Java applets) The Java Plugin for web browsers relies on the cross-platform plugin architecture NPAPI, which had been supported by all major web browsers for over a decade. Google's Chrome version 45 and above have dropped support for NPAPI, and therefore Java Plugin do not work on these browsers anymore.

    Finally Java Applets and Java Web start were completely removed from Oracle Java 11 SE.

    Java 11 SE Release Notes

    The deployment stack, required for Applets and Web Start Applications, was deprecated in JDK 9 and has been removed in JDK 11.

    and

    The appletviewer tool was deprecated in JDK 9 (see JDK-8074165) and removed in this release.

    So if you're using Java 9 or below the appletviewer is available or if you able to download and install an ancient Chrome (less than 45) you can run that applet but Java 11 or above there is no alternative solution just the migration.