我给你一个你想要的用GridBagLayout布局的图形的Java程序,你运行一下看看吧,再对照一下看看你的程序有什么不同.
import java.awt.*;import java.awt.event.*;
public class AAAA extends Frame{
Button b0=new Button("0");
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("3");
AAAA(){
setSize(400, 知键400);
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc = new GridBagConstraints();
卖洞 gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 6;
gbc.weightx = 60;
gbc.fill = GridBagConstraints.HORIZONTAL;
this.add(b0, gbc);
GridBagConstraints gbc_1 中猛枯= new GridBagConstraints();
gbc_1.gridx = 0;
gbc_1.gridy = 1;
gbc_1.gridheight = 4;
gbc_1.weighty = 40;
gbc_1.fill = GridBagConstraints.VERTICAL;
this.add(b1, gbc_1);
GridBagConstraints gbc_2 = new GridBagConstraints();
gbc_2.gridx = 1;
gbc_2.gridy = 1;
gbc_2.gridwidth = 5;
gbc_2.gridheight = 4;
gbc_2.weightx = 50;
gbc_2.weighty = 40;
gbc_2.fill = GridBagConstraints.BOTH;
this.add(b2, gbc_2);
GridBagConstraints gbc_3 = new GridBagConstraints();
gbc_3.gridx = 0;
gbc_3.gridy = 5;
gbc_3.gridwidth = 6;
gbc_3.weightx = 60;
gbc_3.fill = GridBagConstraints.HORIZONTAL;
this.add(b3, gbc_3);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}});
setVisible(true);
}
public static void main(String[] args) {
new AAAA();
}
}