import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
public class GirdBagDemo extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String args[]) {
try {
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Throwable e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GirdBagDemo frame = new GirdBagDemo();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public GirdBagDemo() {
init();
}
public void init() {
this.setTitle("Email注册");
JLabel j1;
JLabel j2;
JLabel j3;
JLabel j4;
JTextField j5;
JTextField j6;
JTextField j7;
JTextField j8;
JPanel j9;
JButton j10;
j1 = new JLabel("邮件地址");
j2 = new JLabel("密 码");
j3 = new JLabel("确认密码");
j4 = new JLabel("手机号码");
j5 = new JTextField();
j6 = new JTextField();
j7 = new JTextField();
j8 = new JTextField();
j9=new JPanel();
j10=new JButton("立即注册");
j9.add(j10);
GridBagLayout layout = new GridBagLayout();
this.setLayout(layout);
this.add(j1);
this.add(j5);
this.add(j2);
this.add(j6);
this.add(j3);
this.add(j7);
this.add(j4);
this.add(j8);
this.add(j9);
GridBagConstraints s= new GridBagConstraints();//定义一个GridBagConstraints,
//是用来控制添加进的组件的显示位置
s.fill = GridBagConstraints.BOTH;
//该方法是为了设置如果组件所在的区域比组件本身要大时的显示情况
//NONE:不调整组件大小。
//HORIZONTAL:加宽组件,使它在水平方向上填满其显示区域,但是不改变高度。
//VERTICAL:加高组件,使它在垂直方向上填满其显示区域,但是不改变宽度。
//BOTH:使组件完全填满其显示区域。
s.gridwidth=2;//该方法是设置组件水平所占用的格子数,如果为0,就说明该组件是该行的最后一个
s.weightx = 1;//该方法设置组件水平的拉伸幅度,如果为0就说明不拉伸,不为0就随着窗口增大进行拉伸,0到1之间
s.weighty=0;//该方法设置组件垂直的拉伸幅度,如果为0就说明不拉伸,不为0就随着窗口增大进行拉伸,0到1之间
layout.setConstraints(j1, s);//设置组件
s.gridwidth=0;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j5, s);
s.gridwidth=2;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j2, s);
s.gridwidth=0;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j6, s);
s.gridwidth=2;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j3, s);
s.gridwidth=0;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j7, s);
s.gridwidth=2;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j4, s);
s.gridwidth=0;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j8, s);
s.gridwidth=0;
s.weightx = 1;
s.weighty=0;
layout.setConstraints(j9, s);
this.setBounds(250,150,400,200);
this.setVisible(true);
}
}
邮箱注册界面(没有实现功能)
最新推荐文章于 2018-09-24 17:15:29 发布