网页嵌入java程序,如何嵌入在网页中的Java小程序?

I am using the following code to embed a Java applet in a web page,

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"

How can I set it to refer the class file in a package in the jar file which I export out?

解决方案

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:

code="com.whitefang34.ImageIconApplet" />

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

}

}

And the packaged jar for the applet contains:

/com/whitefang34/ImageIconApplet.class

/images/WhiteFang34.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值