applet 的小问题:(50分)

S

stuwei

Unregistered / Unconfirmed
GUEST, unregistred user!
以下文件编译成Applet1.class,放在c:/,然后运行Applet1.html,发现提示:"class Applet1.class not found"
Applet1.html内容为
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=GBK">
<title>
HTML Test Page
</title>
</head>
<body>
untitled1.Applet1 will appear below in a Java enabled browser.<br>
<applet
code = "Applet1.class"
codebase = "c:/"
width = "400"
height = "300"
align = "middle"
>
</applet>
</body>
</html>

package untitled1;
import java.awt.*;
import java.applet.*;
import java.lang.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Applet1 extends Applet {
private boolean isStandalone = false;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Applet1() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
public void paint (Graphics g){
g.drawString("Faint!!!",50,50);
g.setColor(Color.GREEN);
g.fill3DRect(1,1,30,30,true);
}
public void stop(){
// System.out.print("Stop");
}
}
 
把package untitled1;去掉 重新编译java文件
或把code = "Applet1.class"改为"untitled1.Applet1.class"
 
提示:"class Applet1.class not found"
我也认为是路径问题。
 
如果你的HTML页面与Class文件在同一个目录下,就不用CodeBase了。
 
路径问题。。。
 
多人接受答案了。
 

Similar threads

顶部