随便练习练习
代码如下:
import java.awt.*;
class aaa extends Frame{
TextField txt=new TextField(20);
Label lbl1=new Label("名称:");
Label lbl2=new Label("备注");
TextArea area=new TextArea();
Button btn0=new Button("确定");
GridBagLayout gb;
GridBagConstraints gbc;
public aaa(String a){
super(a);
gb=new GridBagLayout();
setLayout(gb);
gbc=new GridBagConstraints();
gbc.fill=GridBagConstraints.BOTH;
addC(lbl1,0,0,5,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addC(lbl2,0,5,5,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addC(area,5,0,10,10);
}
public void addC(Component c,int row,int col,int nrow,int ncol){
gbc.gridx=col;
gbc.gridy=row;
gbc.gridwidth=ncol;
gbc.gridheight=nrow;
gb.setConstraints(c,gbc);
add(c);
}
class bbb extends Panel{
}
class ccc{
public static void main(String args[]){
aaa n=new aaa("测试");
bbb m=new bbb();
n.add(m);
m.setName("aaa");
n.setSize(500,300);
n.show();
n.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}