我按照时尚编程百例中第52例,进行建立Applet程序,为什么编译和运行时,出现“cann't find the main class.program will exit!"对话框,不能执行applet。我又参照好多书,还是不行,而且都是出现同样的对话框,不知道为什么?程序代码如下:
package firstapplet;import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class hello extends Applet {
public void paint(Graphics g){
g.drawString("hello",40,40);
}
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 hello() {
}
//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("hello",40,40);
}
是我自己加的,其他都是自动生成的
package firstapplet;import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class hello extends Applet {
public void paint(Graphics g){
g.drawString("hello",40,40);
}
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 hello() {
}
//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("hello",40,40);
}
是我自己加的,其他都是自动生成的
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货