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);
本人初学者,对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);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货