Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在html上运行JApplet,ClassNotFoundException_Java_Html_Applet_Classnotfoundexception_Japplet - Fatal编程技术网

Java 无法在html上运行JApplet,ClassNotFoundException

Java 无法在html上运行JApplet,ClassNotFoundException,java,html,applet,classnotfoundexception,japplet,Java,Html,Applet,Classnotfoundexception,Japplet,我写了一个简单的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

我写了一个简单的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>

但是当我打开web文件时,它捕获了ClassNotFoundException。请帮助我或给我一些建议。非常感谢。

尝试编译
.java
文件以获取
.class
文件,并将其粘贴到
测试/
中。检查是否有错误。

您是否检查了Java控制台的详细错误?我已经检查了,没有错误。您是否认为HTML和
tmp.jar的目录结构和位置对解决此问题很重要?请将该信息包括在内。顺便说一句-1)
g.drawImage(image,0,0,null)
应该是
g.drawImage(image,0,0,this)JComponent
都是一个
ImageObserver
。2)
image=ImageIO.read(新文件(“img.jpg”)小程序的资源需要加载为
URL
,而不是
文件
。优选地,相对于HTML中指定的
codebase
或文档库形成的
URL
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();
            }
        }
    }
}