日期:2014-05-20  浏览次数:20774 次

Dialog问题
Java code
import java.awt.*;

public class jie 
{
    public static void main(String[] args)
    {
        Frame a=new Frame("awbd");
        a.setSize(100,100);
        a.setLocation(0, 0);
        Button B1=new Button("确定");
        Button B2=new Button("取消");
        
        Label L=new Label("你点击了关闭,如果你不保存所编辑的文件,文件将会丢失,你确定继续关闭吗?");
        Dialog D=new Dialog((Frame)a, "警告!!!",true);
        
        D.setSize(200,200);
        D.setLocation(0, 0);
        
        Panel p=new Panel();
        p.setLayout(new GridLayout(1,2));
        
        p.add(B1);
        p.add(B2);
        D.add(L,"center");
        D.add(p,"south");
        
        a.setVisible(true);
        D.setVisible(true);
    }
}


为什么在我编译的时候,对话框没有显示出来?
反而一直提示出现异常IllegalArgumentException

------解决方案--------------------
大小写错误,应该是:
D.add(L, "Center");
D.add(p, "South");

不过建议用:
D.add(L, BorderLayout.CENTER);
D.add(p, BorderLayout.SOUTH);