setSize(450, 339);// 设置窗体大小
setLocationRelativeTo(null);// 窗体居中
contentPane = new JPanel();// 内容面板
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));// 设置布局
setContentPane(contentPane);
JPanel panel = new JPanel(new GridLayout(5, 1, 5, 10));//5行1列的表格布局
panel.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
contentPane.add(panel, BorderLayout.CENTER);//给panel添加边框
JPanel panel_1 = new JPanel();
panel.add(panel_1);
JLabel label = new JLabel("姓名");
panel_1.add(label);
tfName = new JTextField();
panel_1.add(tfName);
tfName.setColumns(10);
JLabel label_2 = new JLabel("学号");
panel_1.add(label_2);
tfNum = new JTextField();
tfNum.setColumns(10);
panel_1.add(tfNum);
rb1 = new JRadioButton("男");
panel_1.add(rb1);
rb1.setSelected(true);//设置单选按钮中,默认选择的按钮
rb2 = new JRadioButton("女");
panel_1.add(rb2);
ButtonGroup bts = new ButtonGroup();//单选按钮需要加入同一个ButonGroup中才能生效
bts.add(rb1);
bts.add(rb2);
JPanel panel_2 = new JPanel();
panel.add(panel_2);
cb1 = new JCheckBox("高等数学");
panel_2.add(cb1);
t1 = new JComboBoxString();
t1.setModel(new DefaultComboBoxModelString(new String[] { "林老师", "赵老师", "孙老师" }));
panel_2.add(t1);
JPanel panel_3 = new JPanel();
panel.add(panel_3);
cb2 = new JCheckBox("世界经济");
panel_3.add(cb2);
t2 = new JComboBoxString();
t2.setModel(new DefaultComboBoxModelString(new String[] { "张老师", "刘老师" }));
panel_3.add(t2);
JPanel panel_4 = new JPanel();
panel.add(panel_4);
cb3 = new JCheckBox("音乐赏析");
panel_4.add(cb3);
t3 = new JComboBoxString();
t3.setModel(new DefaultComboBoxModelString(new String[] { "王老师", "周老师" }));
panel_4.add(t3);
JPanel panel_5 = new JPanel();
panel.add(panel_5);
JButton jbOk = new JButton("确定");
panel_5.add(jbOk);
JButton jbRest = new JButton("重填");
panel_5.add(jbRest);
JPanel panelSouth = new JPanel();
contentPane.add(panelSouth, BorderLayout.SOUTH);
JLabel labe = new JLabel("选课信息");
labe.setHorizontalAlignment(SwingConstants.LEFT);
panelSouth.add(labe);
allInfo = new JTextField();
allInfo.setColumns(30);
panelSouth.add(allInfo);
JPanel panelNorth = new JPanel();
contentPane.add(panelNorth, BorderLayout.NORTH);
JLabel labelTitle = new JLabel("学生选课界面");
labelTitle.setForeground(Color.DARK_GRAY);
labelTitle.setFont(new Font("宋体", Font.BOLD, 20));
panelNorth.add(labelTitle);
//给确定按钮添加事件处理代码
jbOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
StringBuilder info = new StringBuilder();
String name = tfName.getText();
String num = tfNum.getText();
String sex;
if (rb1.isSelected()) {
sex = "男";
} else {
sex = "女";
}
info.append(name + num + sex);
if (cb1.isSelected()) {
String c = cb1.getText();
String t = t1.getSelectedItem().toString();
info.append(" " + c + t);
}
if (cb2.isSelected()) {
String c = cb2.getText();
String t = t2.getSelectedItem().toString();
info.append(" " + c + t);
}
if (cb3.isSelected()) {
String c = cb3.getText();
String t = t3.getSelectedItem().toString();
info.append(" " + c + t);
}
allInfo.setText(info.toString());//把学生信息和选课信息放到文本框
}
});
//给重填按钮 设置事件处理代码
推荐阅读
- redis如何做接口幂等性,redis的multi
- 如何占领电商平台,如何做电商平台
- sqlserver存储结果集,sql存储数据
- phpcms生成首页提示文件错误,phpcms生成首页提示文件错误怎么办
- c语言调用函数用法 c语言调用函数方法
- 关注视频号文案朋友圈,关注微信视频号话术
- linux设置时区命令,linux 设置 时区
- 手游射击类游戏第一人称,手游第一人称射击游戏排行
- 匿名函数定义python 匿名函数定义后的结果