将 Java Applet 嵌入到 .html 文件中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4272666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:13:55  来源:igfitidea点击:

Embedding Java Applet into .html file

javahtmlapplet

提问by

I am having trouble embedding my applet into a webpage. I don't think I'm doing it correctly.

我在将小程序嵌入网页时遇到问题。我不认为我做对了。

*I have my html file in the same directory as my .class files

*我的 html 文件与我的 .class 文件位于同一目录中

My main method is in CardApp class

我的主要方法是在 CardApp 类中

This is my html code

这是我的 html 代码

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>TestJCardBet.html</title>
</head>
<body>
<applet codebase="" code="CardApp.class" height="400" width="500"></applet>
</body>
</html>

采纳答案by Kim Burgaard

Making applets work across a wide range of browsers is surprisingly hard. The tags weren't properly standardized in the early days, so Internet Explorer and Mozilla went separate directions.

让小程序在各种浏览器上工作是非常困难的。早期的标签没有正确标准化,因此 Internet Explorer 和 Mozilla 走向了不同的方向。

Sun developed a generic JavaScript to handle all the specific browser quirks, so that you don't have to worry about browser compatibility.

Sun 开发了一个通用 JavaScript 来处理所有特定的浏览器怪癖,因此您不必担心浏览器兼容性。

Add this to your <head>section:

将此添加到您的<head>部分:

<script src="//www.java.com/js/deployJava.js"></script>

And this to <body>section:

<body>部分:

<script>
    var attributes = {codebase: 'http://my.url/my/path/to/codebase',
                      code: 'my.main.Applet.class',
                      archive: 'my-archive.jar',
                      width: '800', 
                      height: '600'};
    var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
    var version = '1.5'; // JDK version
    deployJava.runApplet(attributes, parameters, version);
</script>

See Java? Rich Internet Applications Deployment Advicefor a detailed explanation of the script and all the possible options.

看到Java了吗?Rich Internet Applications Deployment Advice有关脚本和所有可能选项的详细说明。

回答by Vadzim

I agree that deployJava.jsis preferred approach nowadays.

我同意这deployJava.js是当今的首选方法。

Then follow several old multi-browser tricks for historical completeness.

然后遵循几个旧的多浏览器技巧以确保历史完整性。

https://www.ailis.de/~k/archives/63-How-to-use-Java-applets-in-modern-browsers.html:

https://www.ailis.de/~k/archives/63-How-to-use-Java-applets-in-modern-browsers.html

<object id="testapplet-object" 
        classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
        width="256" height="256"
        codebase="http://java.sun.com/update/1.6.0/jinstall-6u30-windows-i586.cab#Version=1,6,0,0">
  <param name="archive" value="mytest.jar" />
  <param name="code" value="my.package.MyClass" />
  <param name="myParam" value="My Param Value" />
  <embed id="testapplet-embed"
         type="application/x-java-applet;version=1.6"
         width="256" height="256" 
         archive="mytest.jar"
         code="my.package.MyClass" 
         pluginspage="http://java.com/download/"
         myParam="My Param Value" />
  </embed>
</object>

http://joliclic.free.fr/html/object-tag/en/object-java.html(has several variations):

http://joliclic.free.fr/html/object-tag/en/object-java.html(有多种变体):

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
        width="150" height="80">
  <param name="codebase" value="data" >
  <param name="code" value="JitterText">
  <param name="BGCOLOR" value="000000">
  <param name="TEXTCOLOR" value="FF0000">
  <param name="TEXT" value="OJITesting!">
  <param name="SPEED" value="250">
  <param name="RANDOMCOLOR" value="1">

  <!--[if gte IE 7]> <!-->
  <object classid="java:JitterText.class"
          codebase="data"
          type="application/x-java-applet"
          width="150" height="80">
    <param name="code" value="JitterText">
    <!-- Safari browser needs the following param -->
    <param name="JAVA_CODEBASE" value="data">
    <param name="BGCOLOR" value="000000">
    <param name="TEXTCOLOR" value="FF0000">
    <param name="TEXT" value="OJITesting!">
    <param name="SPEED" value="250">
    <param name="RANDOMCOLOR" value="1">
    alt : <a href="data/JitterText.class">JitterText.class</a>
  </object>
  <!--<![endif]-->
  <!--[if lt IE 7]>
    alt : <a href="data/JitterText.class">JitterText.class</a>
  <![endif]-->

</object>