_069_标签_编辑框_单复选框_下拉框

===========================

class Test1
{
	public static void main(String[] args)
	{
		JFrame jFrame = new JFrame("窗口");

		// 创建一个面板
		JPanel jPanel = new JPanel();
		// 把面板添加到窗口中
		jFrame.add(jPanel);
		
		// 用户名标签
		JLabel jLabel = new JLabel("用户名");
		
		// 用户名输入框
		JTextField jTextField = new JTextField(12);// 设置可写长度为12
		
		// 把2个组建都加入面板中
		jPanel.add(jLabel);
		jPanel.add(jTextField);

		// 密码标签
		JLabel jLabel1 = new JLabel("用户名");
		// 密码输入框,要求输入的都是*
		JPasswordField jTextField1 = new JPasswordField(12);// 设置可写长度为12
		// 把2个组建都加入面板中
		jPanel.add(jLabel1);
		jPanel.add(jTextField1);

		// 单选框,如果想选中一个,另一个就不选择,就必须分组
		JLabel sex = new JLabel("性别");
		JRadioButton man = new JRadioButton("男", true);
		JRadioButton woman = new JRadioButton("女");
		
		//分组
		ButtonGroup group = new ButtonGroup();
		group.add(man); // 谁先加进去,谁优先选择(上面2个都写了true的情况下)
		group.add(woman);

		jPanel.add(sex);
		jPanel.add(man);
		jPanel.add(woman);

		// 下拉框
		JLabel city = new JLabel("城市");
		Object[] arr =
		{ "北京", "上海" };
		JComboBox citys = new JComboBox(arr);

		jPanel.add(city);
		jPanel.add(citys);

		// 复选框
		JLabel hospital = new JLabel("兴趣爱好");
		JCheckBox checkBox1 = new JCheckBox("打飞机");
		JCheckBox checkBox2 = new JCheckBox("打人");
		JCheckBox checkBox3 = new JCheckBox("打游戏");

		jPanel.add(checkBox1);
		jPanel.add(checkBox2);
		jPanel.add(checkBox3);

		// 文本框
		JLabel my = new JLabel("个人简介");
		JTextArea area = new JTextArea(20, 20);
		area.setLineWrap(true);// 设置自动换行
		jPanel.add(my);
		jPanel.add(area);

		Tools.setAll(jFrame, 1024, 768);
	}
}

猜你喜欢

转载自blog.csdn.net/yzj17025693/article/details/82812933