GridBagLayout 怎么用啊 到现在还是不会用啊???哪位大侠看看这个程序有问题没有???
import javax.swing.*;import java.awt.*;
public class demo_7
{
public static void main(String[] args)
{
demo_7_1 test=new demo_7_1();
}
}
class demo_7_1 extends JFrame
{
GridBagLayout gridbaglayout=new GridBagLayout();
GridBagConstraints gridbagconstraints;
GridBagConstraints gridbagconstraints1;
JPanel jp;
JButton jbutton1;
JButton jbutton2;
JButton jbutton3;
JButton jbutton4;
JButton jbutton5;
JButton jbutton6;
JButton jbutton7;
public demo_7_1()
{
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(0,0,400,300);
jp=new JPanel();
this.setContentPane(jp);
gridbagconstraints=new GridBagConstraints();
this.getButton();
this.addJpaenl();
gridbaglayout.setConstraints(jbutton1,gridbagconstraints11(0,0,2,2,0,0,0,1,0,0));
gridbaglayout.setConstraints(jbutton2,gridbagconstraints11(6,6,2,2,0,0,0,1,0,0));
}
/*
*初始化按钮代码块
*/
public void getButton()
{
jbutton1=new JButton("jbutton1");
jbutton2=new JButton("jbutton2");
jbutton3=new JButton("jbutton3");
jbutton4=new JButton("jbutton4");
jbutton5=new JButton("jbutton5");
jbutton6=new JButton("jbutton6");
jbutton7=new JButton("jbutton7");
}
/*
*初始化约束代码块
*/
public GridBagConstraints gridbagconstraints11(int x,int y,int w,int h,double w1,double h1,int anchor,int fill,int ipadx,int ipady)
{
gridbagconstraints1=new GridBagConstraints();
gridbagconstraints1.gridx=x;
gridbagconstraints1.gridx=y;
gridbagconstraints1.gridwidth=w;
gridbagconstraints1.gridheight=h;
gridbagconstraints1.weightx=w1;
gridbagconstraints1.weighty=h1;
gridbagconstraints1.anchor=anchor;
gridbagconstraints1.fill=fill;
gridbagconstraints1.ipadx=ipadx;
gridbagconstraints1.ipady=ipady;
return gridbagconstraints1;
}
public void addJpaenl()
{
jp.add(jbutton1);
jp.add(jbutton2);
jp.add(jbutton3);
jp.add(jbutton4);
jp.add(jbutton5);
jp.add(jbutton6);
jp.add(jbutton7);
}
}