2021-01-11

用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("注册页面");
	}

}

代码运行结果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Like Veritas

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值