简体   繁体   中英

Java applet trouble, really simple

I just started learning Java and I encountered some problems with the tag in HTML. Actually I think it's because of the attribute classid, I think I'm not using it correctly. I had some experience with HTML/CSS/Javacript/PHP some time ago so I can say that I can manage those.

I have this Java code:

import java.awt.Graphics;
import java.applet.Applet;

public class app2 extends Applet {
    public void paint(Graphics g){
        g.drawString("This is an applet",50,50);
    }
}

And I have this in HTML:

    <html>
    <head>
        <title> First applet </title>
    </head> 
    <body> 
        <object codetype="application/java" 
            classid="java:app2.class"
            width="300" height="150" ></object>
    </body>
</html>

Both app2.class and the html file are in the same folder, but when I open the HTML file it doesn't show anything. Using the deprecated tag, works though. Could you please tell me what's wrong with this?

You have created the object tag incorrectly. See this link for more information on embedding applets in html pages.

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