java大作业-学生管理系统(2)

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.io.Serializable;

public class StudentJPanel extends JPanel {
    public JTextField text_id,text_name,text_school,text_classId;//学号姓名学校班级文本行
    public JComboBox<String> comboBox_age;//年龄组合框
    private JRadioButton[] radioButtons;//性别选择按钮
    private static String[] age={"2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"};
    private JLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6;
    Font font;

    public StudentJPanel(){
        this.setBorder(new TitledBorder("Students"));
        this.setLayout(new GridLayout(4,3));
        font = new Font("楷体", Font.BOLD, 22);
        this.setFont(font);
        jLabel1 = new JLabel("学号");
        //jLabel1.setSize(30,5);
        this.add(jLabel1);
        jLabel2 = new JLabel("姓名");
        //jLabel2.setSize(30,5);
        this.add(jLabel2);
        jLabel3 = new JLabel("班级");
        //jLabel3.setSize(30,5);
        this.add(jLabel3);
        this.add(this.text_id = new JTextField(" 学号 : ",20));
        this.add(this.text_name = new JTextField(" 姓名 : ",20));
        this.add(this.text_classId = new JTextField(" 班级 : ",20));
        jLabel4 = new JLabel("学校");
        this.add(jLabel4);
        jLabel5 = new JLabel("性别");
        this.add(jLabel5);
        jLabel6 = new JLabel("年龄");
        this.add(jLabel6);
        this.add(this.text_school = new JTextField(" 学校 : "));
        String[] str = {"男","女"};
        JPanel jPanel = new JPanel(new GridLayout(1,2));//性别面板
        this.add(jPanel);
        ButtonGroup buttonGroup = new ButtonGroup();
        this.radioButtons = new JRadioButton[str.length];
        for (int i = 0; i < this.radioButtons.length; i++) {
            jPanel.add(this.radioButtons[i] = new JRadioButton(str[i]));
            buttonGroup.add(this.radioButtons[i]);
        }
        this.radioButtons[0].setSelected(true);//默认男选中

        this.add(this.comboBox_age = new JComboBox<String>(StudentJPanel.age));

    }
    public void set(Student stu){
        if (stu == null){
            return;
        }
        this.text_id.setText(stu.id);
        this.text_name.setText(stu.name);
        this.text_classId.setText(stu.classId);
        this.text_school.setText(stu.school);
        if (stu.sex.equals("男"))
            this.radioButtons[0].setSelected(true);
        else
            this.radioButtons[1].setSelected(true);
        this.comboBox_age.setSelectedItem(stu.age);

    }

    public Student get(){
        String sex = radioButtons[0].isSelected()?radioButtons[0].getText():radioButtons[1].getText();
        return new Student(text_id.getText(),text_name.getText(),sex,(String)comboBox_age.getSelectedItem(),text_school.getText(),text_classId.getText());
    }
}
class Student implements Serializable {
    public String id;
    public String sex;
    public String name;
    public String age;
    public String school;
    public String classId;

    public Student(String id, String name, String sex, String age, String school, String classId) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.classId = classId;
        this.school = school;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return /*"学号  " +*/ id +
                /*", 姓名  " +*/ name +"  "+
                /*", 性别  " +*/ sex +"  "+
                /*", 年龄  " +*/ age +"岁 "+
                /*", 学校  " +*/ school +
                /*", 班级  " +*/ classId ;
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值