使用 HTML/JavaScript 在网页中显示小程序
我对 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试下面的代码
或
祝你好运...
Try below code
OR
Good Luck...
使用 deployJava.js 编写小程序元素。该脚本受 Oracle 支持,并且将:
object
/embed
或 < code>applet 元素是该浏览器最知名的元素。其他注意事项:
PendulumApplet.class
还是Applet1.class
?在国际论坛上调试问题而不引入对小程序类名称的怀疑已经够困难的了。code
属性中的.class
扩展是可以接受的,但不正确。该值应该是表示类的完全限定名称的字符串。 EGjavax.swing.JApplet
与javax.swing.JApplet.class
相反。而不是
)
Use deployJava.js to write the applet element. The script is supported by Oracle, and will:
object
/embed
orapplet
element as is best known for that browser.Other notes:
PendulumApplet.class
orApplet1.class
? It is hard enough to debug problems on international forums without introducing doubt about the name of the applet class..class
extension in thecode
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 tojavax.swing.JApplet.class
.<html>
as opposed to<Html>
)尽管我自己没有这样做,但我的 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)
我自己也遇到了同样的问题。
使用
不起作用,但使用
谷歌浏览器和 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.