用GUI组件实现注册页面
public class RegisterForm extends JFrame {
JTextField text;
JButton button;
JCheckBoxMenuItem checkBox1, checkBox2, checkBox3;
JRadioButton radio1, radio2;
ButtonGroup group;
JComboBox comBox;
JTextArea area;
public RegisterForm() {
init();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init() {
setLayout(new FlowLayout());
Box baseBox, box1, box2, box3, box4;
baseBox = Box.createVerticalBox();
add(baseBox);
box1 = Box.createHorizontalBox();
box2 = Box.createHorizontalBox();
box3 = Box.createHorizontalBox();
box4 = Box.createHorizontalBox();
baseBox.add(box1);
baseBox.add(Box.createVerticalStrut(16));
baseBox.add(box2);
baseBox.add(Box.createVerticalStrut(16));
baseBox.add(box3);
baseBox.add(Box.createVerticalStrut(16));
baseBox.add(box4);
box1.add(new JLabel("姓名"));
text = new JTextField(10);
box1.add(text);
button = new JButton("确定");
box1.add(button);
box2.add(new JLabel("爱好"));
checkBox1 = new JCheckBoxMenuItem("喜欢音乐");
checkBox2 = new JCheckBoxMenuItem("喜欢旅游");
checkBox3 = new JCheckBoxMenuItem("喜欢篮球");
box2.add(checkBox1);
box2.add(checkBox2);
box2.add(checkBox3);
box2.add(new JLabel("性别"));
group = new ButtonGroup();
radio1 = new JRadioButton("男");
radio2 = new JRadioButton("女");
group.add(radio1);
group.add(radio2);
box2.add(radio1);
box2.add(radio2);
box3.add(new JLabel("选择学历"));
comBox = new JComboBox();
comBox.addItem("高中");
comBox.addItem("大学");
comBox.addItem("研究生");
box3.add(comBox);
box4.add(new JLabel("自我介绍"));
area = new JTextArea(6, 12);
box4.add(new JScrollPane(area));
}
}
public class Test {
public static void main(String args[]) {
RegisterForm win = new RegisterForm();
win.setBounds(100, 100, 310, 260);
win.setTitle("注册页面");
}
}
代码运行结果