使用 HTML/JavaScript 在网页中显示小程序

发布于 2024-12-28 10:25:49 字数 991 浏览 4 评论 0原文

我对 HTML 和 applet 的经验很少。我已经尝试了一些在网上找到的东西,但无法使我的 Java 小程序在 Web 浏览器中运行(它在 Eclipse 中运行)。

我已将 HTML 文件与小程序的所有 Java 类文件放在同一文件夹中。我目前正在使用 Safari,但希望该小程序能够在大多数流行的浏览器中运行。

如何使用 HTML/JavaScript 在网页上显示 Java 小程序?任何人都可以提供任何提示/建议吗?

下面是我尝试的 HTML 代码。

尝试 1:

<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<embed code="PendulumApplet.class"
  width="200" height="200"
  type="application/x-java-applet;version=1.5.0"
  pluginspage="http://java.sun.com/j2se/1.5.0/download.html"/></embed>
</Body>
</Html>

尝试 2:

<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>

<Body>
<br>
<br>
<OBJECT 
  classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
  width="200" height="200">
  <PARAM name="code" value="Applet1.class">
</OBJECT>
</Body>
</Html> 

I have very little experience with HTML and applets. I have tried several of the things I found online, but am unable to make my Java applet run in a web browser (it functions in eclipse).

I have put the HTML file in the same folder as all of my Java class files for the applet. I am currently using Safari, but would like the applet to work in most any popular browser.

How can I display a java applet on a webpage using HTML/JavaScript? Can anyone offer any tips/advice?

Below is my attempted HTML code.

Attempt 1:

<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<embed code="PendulumApplet.class"
  width="200" height="200"
  type="application/x-java-applet;version=1.5.0"
  pluginspage="http://java.sun.com/j2se/1.5.0/download.html"/></embed>
</Body>
</Html>

Attempt 2:

<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>

<Body>
<br>
<br>
<OBJECT 
  classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
  width="200" height="200">
  <PARAM name="code" value="Applet1.class">
</OBJECT>
</Body>
</Html> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦明 2025-01-04 10:25:49

尝试下面的代码

 <APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
 </APPLET>

 <object width="400" height="400" data="helloworld.class"></object> 

祝你好运...

Try below code

 <APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
 </APPLET>

OR

 <object width="400" height="400" data="helloworld.class"></object> 

Good Luck...

征﹌骨岁月お 2025-01-04 10:25:49

使用 deployJava.js 编写小程序元素。该脚本受 Oracle 支持,并且将:

  1. 检查用户是否具有所需的最低 Java,如果没有,则提示他们安装。
  2. 编写 object/embed 或 < code>applet 元素是该浏览器最知名的元素。

其他注意事项:

  1. PendulumApplet.class还是Applet1.class?在国际论坛上调试问题而不引入对小程序类名称的怀疑已经够困难的了。
  2. code 属性中的 .class 扩展是可以接受的,但不正确。该值应该是表示类的完全限定名称的字符串。 EG javax.swing.JAppletjavax.swing.JApplet.class 相反。
  3. HTML 元素名称应全部小写(例如 而不是
  4. 您在 Java 控制台中看到什么输出?在浏览器中调试小程序时,务必确保 Java 控制面板配置为在发现小程序(或 JWS 应用程序)时弹出打开控制台。

Use deployJava.js to write the applet element. The script is supported by Oracle, and will:

  1. Check the user has the minimum required Java, prompting them to install if not, before..
  2. Writing the object/embed or applet element as is best known for that browser.

Other notes:

  1. Is it PendulumApplet.class or Applet1.class? It is hard enough to debug problems on international forums without introducing doubt about the name of the applet class.
  2. The .class extension in the code attribute is tolerated, but not correct. The value should be a string representing the Fully Qualified Name of the class. E.G. javax.swing.JApplet as opposed to javax.swing.JApplet.class.
  3. HTML element names should be all lower case (e.g. <html> as opposed to <Html>)
  4. What output do you see in the Java console? When debugging applets in a browser, it is vital ensure the Java Control Panel is configured to pop open the console on discovering an applet (or JWS app.).
清欢 2025-01-04 10:25:49

尽管我自己没有这样做,但我的 Java 教科书提供了嵌入的大纲:


(括号内为可选参数)

Although I have not done so myself, my Java textbook provides this outline for an embed:

<applet
code = "ClassName.class"
width = 250
height = 50
[archive = archivefile]
[vspace = vertical_margin]
[hspace = horz_margin]
[algin = applet_alignment]
[alt = alt_text]
>
</applet>

(Optional parameters in brackets)

满地尘埃落定 2025-01-04 10:25:49

我自己也遇到了同样的问题。

使用 不起作用,但使用 > 似乎有效。

谷歌浏览器和 IE。

I was having this SAME issue myself.

Using <applet code=""></applet> doesn't work, but <Applet> or <APPLET> seems to work.

Google Chrome and IE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文