要放在html里面才能运行的
直接用jbuilder或者java.exe来运行当然不行了。

解决方案 »

  1.   

    要放在html里面才能运行的
    直接用jbuilder或者java.exe来运行当然不行了。
      

  2.   

    除非你自己加一个 main 函数
    或者用 Appletviewer 运行
      

  3.   

    在html里,把这段放在你需的位置,打开页面,OK!
    <applet width="450" height="300" code="SquareInt.class">
    </applet>
      

  4.   

    我觉得从出错信息来看,应该是没有在浏览器或AppletViewer里执行
    但是我也没有看到你重载void paint(Graphics g)方法呀
      

  5.   

    在public class SquareInt extends JApplet {
      public void init()
    中间加上
    public void paint(Graphics g) {
    然后在你的SquareInt.class同目录下建一个html文件﹐用
    <applet width="450" height="300" code="SquareInt.class">
    </applet>
    嵌入﹐然后执行这个html文件就可以显示了。
      

  6.   

    没有仔细看就盲目的发言﹐上面的帖子是错的﹐你的程序是正确的﹐而我说的方法不能显示你的运行结果﹐我直接在Jcreatoe下运行你的程序结果是
    the result of 1is 1/n the result of 2is 4/n the result 3is 9/n.....
      

  7.   

    要用浏览器或appletviewer里运行。
      

  8.   

    这个一个程序片,没有main()方法入口,可以置于ie浏览器里面显示
    若想在java程序运行里面显示,可以将这个程序片窗口放入一个Frame界面显示其结果,添加代码如下:
    在程序头添加:
    import java.awt.*;
    import java.awt.event.*;
    在程序尾最后一个}符号前添加:
      // To close the application:
      static class WL extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
          System.exit(0);
        }
      }
      // A main() for the application:
      public static void main(String[] args) {
        SquareInt applet = new SquareInt();
        Frame aFrame = new Frame("SquareInt");
        aFrame.addWindowListener(new WL());
        aFrame.add(applet, BorderLayout.CENTER);
        aFrame.setSize(300,200);
        applet.init();
        applet.start();
        aFrame.setVisible(true);
      }此程序执行结果为:
    The result of 1is 1/nThe result of 2is 4/nThe result of 3is 9/nThe result of 4is 16/nThe result of 5is 25/nThe result of 6is 36/nThe result of 7is 49/nTh……