如何在网页中嵌入 Java 小程序? [英] How to embed a Java applet in a web page?
问题描述
我正在使用以下代码在网页中嵌入 Java 小程序,
I am using the following code to embed a Java applet in a web page,
<APPLET CODE="main.class" WIDTH=500 HEIGHT=80 archive='testing.jar'>
</APPLET>
但问题是,我的小程序的类文件在一个名为 environment
的包中,这意味着我的 main.class
在文件夹环境中.
But the problem is, the class file for my applet is in a package named environment
,
which means my main.class
is inside a folder environment.
浏览器显示我使用时无法搜索我的类文件的错误信息
The browser show me the error message that it can't search my class file when I use
CODE="main.class"
如何将其设置为在导出的 jar 文件中引用包中的类文件?
How can I set it to refer the class file in a package in the jar file which I export out?
推荐答案
你可能想看看 部署小程序 和 使用 Applet 标签部署.这是小程序的一个小工作示例,可能会对您有所帮助.该页面的 HTML 很简单:
You'll probably want to take a look at Deploying an Applet and Deploying With the Applet Tag. Here's a small working example of an applet that might help you. The HTML for that page is simply:
<applet width="200" height="200" archive="ImageIconApplet.jar"
code="com.whitefang34.ImageIconApplet" />
小程序源代码为:
package com.whitefang34;
public class ImageIconApplet extends JApplet {
public void init() {
URL url = getClass().getResource("/images/WhiteFang34.jpg");
ImageIcon icon = new ImageIcon(url);
JLabel label = new JLabel(icon, JLabel.CENTER);
add(label);
}
}
小程序的打包的jar包含:
/com/whitefang34/ImageIconApplet.class
/images/WhiteFang34.jpg
这篇关于如何在网页中嵌入 Java 小程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!