我按照时尚编程百例中第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);
  }
是我自己加的,其他都是自动生成的

解决方案 »

  1.   

    我在JBuilder8.0里试了可以运行没有问题你得指定运行文件的类型,是Applet指定这个文件
      

  2.   

    snmmc(冬瓜(菜鸟版)) ,不好意思,我是初学者,我不知道你说的指定都是从哪里指定的?但我在run-optimize project-run 下的类型已经是Applet,而且是灰色的不能改,不过我选了“html file"之后就可以了。问题是否出在这里,谢谢你。等待你再次回复!