简体   繁体   English

Java-Applet根本不显示?

[英]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. 好的,所以我做了一个小程序教程,并且我读到要运行一个小程序需要init()方法。 And it does. 确实如此。 At least in my IDE (Eclipse). 至少在我的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). Applet Viewer在运行我的applet时没有问题,当我尝试在HTML中执行<applet>标记时,不会显示任何内容,但它的作用就好像是有什么东西(标记更改了文本位置)。 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). 即使删除width / height参数,我也会得到相同的结果(它不会显示在页面上)。 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

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

The applet tag is deprecated and the object tag should be used instead. applet标签已弃用,应改为使用object标签。 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. 一些浏览器不支持applet标记,这可能就是为什么您看不到applet的原因,而object标记现在应该可以在所有这些标记上使用。

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. 请参阅此链接此链接以获取更多示例和信息。

As mentioned earlier, it is not recommended to use applet tag. 如前所述,不建议使用applet标签。 If you are sure that end user browsers will have the JavaScript enabled, you can use this simple way to deploy your applet: 如果您确定最终用户浏览器将启用JavaScript,则可以使用以下简单方法来部署小程序:

<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). 上面的代码将使用一个参数(fontSize)在JRE 1.6.0或更高版本上启动Java 2D applet。

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). 对于像我这样搜索Google的人们来说,这只是一个最新答案(许多方面在Java Web Start和Java Applets方面已经发生了变化)。

Below cases might be a reason your Java applet web page is not visible: 以下情况可能是您的Java applet网页不可见的原因:

Chrome no longer supports NPAPI (technology required for Java applets) Chrome不再支持NPAPI(Java小程序所需的技术)

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. 用于Web浏览器的Java插件依赖于跨平台插件体系结构NPAPI,十年来,所有主流Web浏览器都一直支持该框架。 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. Google的Chrome版本45(计划于2015年9月发布)放弃了对NPAPI的支持,从而影响了Silverlight,Java,Facebook Video和其他类似基于NPAPI的插件。 https://www.java.com/en/download/faq/chrome.xml https://www.java.com/en/download/faq/chrome.xml

Firefox limits NPAPI support (technology required for Java applets) Firefox限制了NPAPI支持(Java小程序所需的技术)

The 64-bit version of Firefox does not support NPAPI plug-ins, including Java. Firefox的64位版本不支持NPAPI插件,包括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. 从Firefox 52(2017年3月发布)开始,插件支持仅限于Adobe Flash,并放弃了对NPAPI的支持,这会影响Java,Silverlight和其他类似基于NPAPI的插件。 https://java.com/en/download/help/firefox_java.xml https://java.com/en/download/help/firefox_java.xml

It looks like Internet Explorer is the best bet as of now. 到目前为止,Internet Explorer似乎是最好的选择。

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

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