如何嵌入在网页中的Java小程序? [英] How to embed a Java applet in a web page?

查看:432
本文介绍了如何嵌入在网页中的Java小程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code嵌入在网页中的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>

但问题是,我的小程序的类文件是在一个名为环境包,
这意味着我的 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 并的部署利用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" /> 

Applet源$ C ​​$ c是:

The applet source code is:

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);
    }
}

和applet的包装罐包括:

And the packaged jar for the applet contains:

/com/whitefang34/ImageIconApplet.class
/images/WhiteFang34.jpg

这篇关于如何嵌入在网页中的Java小程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆