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