简体   繁体   中英

Cant run JApplet on html, ClassNotFoundException

I wrote a simple JApplet and I want to run it on my website. I pack it into a .jar file and use applet tag on html. This is my 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:

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. Please help or give me some advice. Thanks alot.

Try compiling the .java file to get the .class file and paste it in test/ . Check if it words.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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