//我想要的结果是:启动一个test,窗口显示的名字就是"test"+"该窗口的标号num".结果却不是,请指教
import java.awt.*;
import java.awt.event.*;public class test extends Frame {
static int num;

test() {
super("Test"+(++num));
this.setVisible(true);
this.setBounds(100,100,40,40);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

public static void main(String[] args) {
new test();
}
}

解决方案 »

  1.   

    System.exit(0); 
    直接退出了?
      

  2.   

    全局变量有默认值我执行你的没有问题,我的jdk1.5
      

  3.   

    多开几个test就不行了num始终是1
      

  4.   

    我也是jdk1.5
    我是想:启动第几个test,窗口名字就显示test几。
      

  5.   

    //:TestFrame.java
    import java.awt.*;
    import java.awt.event.*;public class TestFrame extends Frame {
        static int num;//存储窗口大小    TestFrame() {
            super("Test "+(++num));//这里字符串"Test "中Test后加了一个空格,这只是为了测试,可以把这个空格删去。
            //setBounds()的第3个、第4个参数是为了调节窗后的大小,把第3个数设置得稍大些,这样才能够看清楚标题。
            this.setBounds(300,300,240,50);
            this.setVisible(true);//这一句最好放在setBounds的后面
            //this.setSize(300,200);
            //this.setLocation(240,100);
            this.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
        }    public static void main(String[] args) {
            int nums=0;//存储窗口的个数
            try{
                if(args!=null){
                    nums=Integer.parseInt(args[0]);
                }
            }catch(Exception e){
                System.err.println("请在参数中输入窗口的个数(int型):");
            }
            for(int i=1;i<=nums;i++){
                new TestFrame();
            }
        }
    }
      

  6.   

    num是static类型的,可以不用初始化,系统会默认初始化为  0 .
      

  7.   

    8楼中我的程序这样运行:
    c:\>java TestFrame 3
    结果会同一个位置打开三个窗口。但是关掉一个窗口时会把三个窗口都关掉。
      

  8.   

    我在eclipse中运行了一下,显示:“请在参数中输入窗口的个数(int型):”但输入不进数字!怎么回事?