我写了一个简单的JApplet,我想在我的网站上运行它。我把它打包成一个.jar文件并在html上使用applet标签。这是我的HTML:
<html>
<applet code="main.class"
codebase="test/"
archive="tmp.jar"
width="600" height="95">
<param name="type" value="hello">
<param name="IP" value="127.0.0.1">
</html>
这是我的main.java:
public class main extends JApplet{
public String str, IP;
public ImagePanel panel;
protected void loadAppletParameters(){
String at = getParameter("type");
str = (at != null) ? at : "world";
at = getParameter("IP");
IP = (at != null) ? at : "127.0.0.1";
}
public void init(){
loadAppletParameters();
System.out.println("hi: ");
panel = new ImagePanel();
this.add(panel);
}
public class ImagePanel extends JPanel{
private BufferedImage image;
public ImagePanel() {
try {
image = ImageIO.read(new File("img.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, null);
}
public void change_image(String path){
try {
image = ImageIO.read(new File(path));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
但是当我打开web文件时它捕获了ClassNotFoundException。请帮忙或给我一些建议。非常感谢。
答案 0 :(得分:2)
尝试编译.java
文件以获取.class
文件并将其粘贴到test/
中。检查是否有文字。