简体   繁体   English

创建 Java 小程序以在浏览器中启动

[英]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:这是我的Java代码:

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:这是我的 HTML 代码:

<!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.我希望会发生的是浏览器会启动并显示 HTML,但我唯一能够运行的想法是 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.编辑:为了让事情更清楚,我正在尝试运行此代码,以便它通过浏览器运行,而不仅仅是 AppletViewer。

Neither Chrome nor Firefox are no longer supported NPAPI. Chrome 和 Firefox 都不再支持 NPAPI。

Java and Firefox Browser Java 和 Firefox 浏览器

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. Firefox 不再提供 NPAPI 支持(Java 小程序所需的技术) 截至 2018 年 9 月,Firefox 不再提供支持 NPAPI(运行 Java 小程序所需的技术)的版本。 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.用于 Web 浏览器的 Java 插件依赖于跨平台插件架构 NPAPI,十多年来,所有主要 Web 浏览器都支持该架构。 The 64 bit version of Firefox has never supported NPAPI, and Firefox version 52ESR is the last release to support the technology. 64 位版本的 Firefox 从未支持 NPAPI,而 Firefox 版本 52ESR 是支持该技术的最后一个版本。 It is below the security baseline, and no longer supported.它低于安全基线,不再受支持。

Java and Google Chrome Browser Java 和 Google Chrome 浏览器

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. Chrome 不再支持 NPAPI(Java 小程序所需的技术) Web 浏览器的 Java 插件依赖于跨平台插件架构 NPAPI,该架构已被所有主要 Web 浏览器支持十多年。 Google's Chrome version 45 and above have dropped support for NPAPI, and therefore Java Plugin do not work on these browsers anymore.谷歌的 Chrome 45 及以上版本已经放弃了对 NPAPI 的支持,因此 Java 插件不再在这些浏览器上工作。

Finally Java Applets and Java Web start were completely removed from Oracle Java 11 SE.最后,Java Applets 和 Java Web start 从 Oracle Java 11 SE 中完全删除。

Java 11 SE Release Notes Java 11 SE 发行说明

The deployment stack, required for Applets and Web Start Applications, was deprecated in JDK 9 and has been removed in JDK 11. Applet 和 Web Start 应用程序所需的部署堆栈在 JDK 9 中已弃用,并已在 JDK 11 中删除。

and

The appletviewer tool was deprecated in JDK 9 (see JDK-8074165) and removed in this release. appletviewer 工具在 JDK 9 中被弃用(参见 JDK-8074165)并在此版本中被删除。

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.因此,如果您使用的是 Java 9 或更低版本,appletviewer 可用,或者如果您能够下载并安装一个古老的 Chrome(小于 45),您可以运行该小程序,但 Java 11 或更高版本没有替代解决方案,只有迁移。

I'm not sure what you are trying to do, but here some hints.我不确定你要做什么,但这里有一些提示。 If you want to test some applets install an old jdk 1.6.x or Java 8 (avoid jdk 7).如果您想测试一些小程序,请安装旧的 jdk 1.6.x 或 Java 8(避免使用 jdk 7)。 Use Firefox esr 52.9使用 Firefox esr 52.9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM