关于java 的GridBagConstraints

shiwenmao123 2009-11-25 02:17:47
stuframe.add(this,BorderLayout.WEST);为什么不加这句面板中所添加的按钮就显示不出来???这个this代表什么??
本人初学者,对JAVA的理解还很浅,见笑了,呵呵。。



public class studentmanageframe extends JPanel {
private static final long serialVersionUID = 1L;
static final int WIDTH = 400;
static final int HEIGHT = 200;
JFrame stuframe;
public void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h)
{
constraints.gridx = x;
constraints.gridy = y;
constraints.gridwidth = w;
constraints.gridheight = h;
add(c,constraints);
}
public studentmanageframe()
{
stuframe = new JFrame();
stuframe.setTitle("学生信息管理窗口");
stuframe.setSize(WIDTH, HEIGHT);
stuframe.setResizable(false);
stuframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screensize = kit.getScreenSize();
int width = screensize.width;
int height = screensize.height;
int x = (width-WIDTH)/2;
int y = (height-HEIGHT)/2;
stuframe.setLocation(x, y);
stuframe.setVisible(true);
JButton comone = new JButton("计算机一班学生信息系统");
JButton comtwo = new JButton("计算机二班学生信息系统");
JButton comthree = new JButton("计算机三班学生信息系统");
JButton comfour = new JButton("计算机四班学生信息系统");
JButton comfive = new JButton("计算机五班学生信息系统");
JButton comsix = new JButton("计算机六班学生信息系统");
JLabel title = new JLabel("学生信息系统主界面");
JLabel banket1 = new JLabel();
JLabel banket2 = new JLabel();
GridBagLayout lay = new GridBagLayout(); // ???????
setLayout(lay); //???????
stuframe.add(this,BorderLayout.WEST); //?????????
JPanel jp =new JPanel();
jp.setLayout(new GridLayout(1,3));
jp.add(banket1);
jp.add(title);
jp.add(banket2);
stuframe.add(jp,BorderLayout.NORTH);
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.EAST;
constraints.weightx = 2;
constraints.weighty = 4;
add(comone,constraints,0,1,1,1);
add(comtwo,constraints,1,1,1,1);
add(comthree,constraints,0,2,1,1);
add(comfour,constraints,1,2,1,1);
add(comfive,constraints,0,3,1,1);
add(comsix,constraints,1,3,1,1);
...全文
188 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
feipigzi 2011-03-21
  • 打赏
  • 举报
回复
this表示当前的类 对应你的代码就是 studentmanageframe extends JPanel

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧