[英]Cant run JApplet on html, ClassNotFoundException
我寫了一個簡單的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。 請幫助或給我一些建議。 非常感謝。
嘗試編譯.java
文件以獲得.class
文件並將其粘貼到test/
。 檢查是否單詞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.