简体   繁体   English

无法在HTML上运行JApplet,ClassNotFoundException

[英]Cant run JApplet on html, ClassNotFoundException

I wrote a simple JApplet and I want to run it on my website. 我写了一个简单的JApplet,我想在我的网站上运行它。 I pack it into a .jar file and use applet tag on html. 我将其打包到一个.jar文件中,并在html上使用applet标签。 This is my html: 这是我的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>

And this is my main.java: 这是我的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();
            }
        }
    }
}    

But it caught the ClassNotFoundException when I opened the web file. 但是,当我打开Web文件时,它捕获了ClassNotFoundException。 Please help or give me some advice. 请帮助或给我一些建议。 Thanks alot. 非常感谢。

Try compiling the .java file to get the .class file and paste it in test/ . 尝试编译.java文件以获得.class文件并将其粘贴到test/ Check if it words. 检查是否单词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM