⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zymodifysituation.java

📁 学生管理(部分源代码仅供参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (info.containsKey(number)) {
                jButton2.setEnabled(true); // 如果输入的学号存在于散列表中,将“录入修改”按// 钮设为黑色即可用状态(modify为“录入修改”按// 钮的name属性值)
                zystudent cperson = (zystudent) info.get(number);
                jTextField2.setText(cperson.name); //将获取到的zsStudent类的成员变量name的值(stu.getName())显示在姓名文本框中(使用setText()方法)。
                jTextField3.setText(cperson.discipling); //将获取到的zsStudent类的成员变量discipling的值显示在专业文本框中。
                jTextField4.setText(cperson.grade); //将获取到的zsStudent类的成员变量grade的值显示在年级文本框中。
                jTextField5.setText(cperson.borth); //将获取到的zsStudent类的成员变量borth的值显示在出生文本框中。

                if (cperson.getsex().equals("男")) { // 如果获取到的zsStudent类的成员变量sex的值等于“男”
                    jRadioButton1.setSelected(true); // 选中“男”单选按钮(“男”单选按钮组件的名称为male)
                } else {
                    jRadioButton2.setSelected(true); // 选中“女”单选按钮(“女”单选按钮组件的名称为female)
                }
            } else { // 否则如果输入的学号不存在于散列表中
                jButton2.setEnabled(false); // 将“录入修改”按钮变为不可使用状态
                // 弹出“警告”对话框提示用户"该学号不存在!";
                String warning = "该学号不存在!";
                JOptionPane.showMessageDialog(this, warning, "警告",
                                              JOptionPane.WARNING_MESSAGE);
                jTextField2.setText(null); // 使用setText(null)方法将姓名文本框清空
                jTextField3.setText(null); /// 将专业文本框清空
                jTextField4.setText(null); /// 将年级文本框清空
                jTextField5.setText(null); /// 将出生文本框清空
            }
        }

        else { // 如果number的长度不大于0,即没有输入学号
            jButton2.setEnabled(false); //将“录入修改”按钮设置为不可使用状态。modify为“录//入修改”按钮的name属性值
            // 弹出“警告”对话框,提示用户"必须输入学号!"
            String warning = "必须输入学号!";
            JOptionPane.showMessageDialog(this, warning, "警告",
                                          JOptionPane.WARNING_MESSAGE);
            jTextField2.setText(null); // 使用setText(null)方法将姓名文本框清空
            jTextField3.setText(null); /// 将专业文本框清空
            jTextField4.setText(null); /// 将年级文本框清空
            jTextField5.setText(null); /// 将出生文本框清空
        }
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        String number = "";
        number = jTextField1.getText();

        if (number.length() > 0) { // 如果number的长度大于0,即输入了学号
            try { // 读入散列表
                inOne = new FileInputStream(file);
                inTwo = new ObjectInputStream(inOne);
                info = (Hashtable) inTwo.readObject();
                inOne.close();
                inTwo.close();
            } catch (Exception ee) {
            }
            if (info.containsKey(number)) { // 如果输入的学号存在于散列表中
                // 弹出“警告”对话框,提示用户
                String question = "该生基本信息已存在,您想修改他)她)的信息吗?";

                JOptionPane.showMessageDialog(this, question, "警告",
                                              JOptionPane.QUESTION_MESSAGE);

                // 弹出“确认”对话框,提示用户"该生基本信息将被修改!"
                String m = "该生基本信息将被修改!";
                int ok = JOptionPane.showConfirmDialog(this, m, "确认",
                        JOptionPane.YES_NO_OPTION,
                         JOptionPane.INFORMATION_MESSAGE);
                if (ok == JOptionPane.YES_OPTION) { // 如果用户选择“是”,将学生信//息保存到散列表中。
                    String name = jTextField2.getText(); // 声明String类对象name,并将姓名文本框中的内容赋值给name
                    String discipling = jTextField3.getText(); // 声明String类对象discipling,并将专业文本框中的内容赋给
                    // discipling
                    String grade = jTextField4.getText(); // 声明String类对象grade,并将年级文本框中的内容赋值给grade
                    String birth = jTextField5.getText(); // 声明String类对象borth,并将出生文本框中的内容赋值给borth
                    String sex = null;
                    if (jRadioButton1.isSelected()) { // 如果“男”单选按钮被选中
                        sex = jRadioButton1.getText(); // 将“男”单选按钮的标签只赋给sex
                    } else { // 否则如果“女”单选按钮被选中
                        sex = jRadioButton2.getText(); // 将“女”单选按钮的标签只赋给sex

                    }
                    zystudent cperson = new zystudent();
                    cperson.setNumber(number); //将zsStudent类中的成员变量number赋值为number变量的值(使用方//法setNumber())
                    cperson.setName(name); //将zsStudent类中的成员变量name赋值为name变量的值
                    cperson.setDiscipling(discipling); //将zsStudent类中的成员变量discipling赋值为discipling变量的值
                    cperson.setGrade(grade); //将zsStudent类中的成员变量grade赋值为grade变量的值
                    cperson.setBorth(birth); //将zsStudent类中的成员变量borth赋值为borth变量的值
                    cperson.setsex(sex); //将zsStudent类中的成员变量sex赋值为sex变量的值

                    try {
                        outOne = new FileOutputStream(file);
                        outTwo = new ObjectOutputStream(outOne);
                        info.put(number, cperson);
                        outTwo.writeObject(info);
                        outTwo.close();
                        outOne.close();
                        jTextField1.setText(null); // 使用setText(null)方法将学号文本框清空
                        jTextField2.setText(null); // 使用setText(null)方法将姓名文本框清空
                        jTextField3.setText(null); // 将专业文本框清空
                        jTextField5.setText(null); // 将年级文本框清空
                        jTextField5.setText(null); // 将出生文本框清空
                    } catch (Exception ee) {
                        System.out.println(ee);
                    }
                    jButton2.setEnabled(false);
                } else if (ok == JOptionPane.NO_OPTION) { // 如果用户选择的是“否”
                    jButton2.setEnabled(true); // 将“录入修改”按钮设置为可用状态。
                }
            } else { // 否则如果输入的学号不存在于散列表中
                // 弹出“警告”对话框
                String warning = "没有该学号基本信息,不能修改!";
                JOptionPane.showMessageDialog(this, warning, "警告",
                                              JOptionPane.WARNING_MESSAGE);
                jButton2.setEnabled(false); // 将“录入修改”按钮设为不可用状态
            }
        } else { // 否则如果number的长度不大于0,即没有输入学号

            // 弹出“警告”对话框,提示用户"必须输入学号"
            String warning = "必须输入学号";
            JOptionPane.showMessageDialog(this, warning, "警告",
                                          JOptionPane.WARNING_MESSAGE);
            jButton2.setEnabled(false); // 将“录入修改”按钮设置为不可用状态

        }
    }
}

    class zymodifysituation_jButton1_actionAdapter implements ActionListener {
    private zymodifysituation adaptee;
    zymodifysituation_jButton1_actionAdapter(zymodifysituation adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}


    class zymodifysituation_jButton2_actionAdapter implements ActionListener {
        private zymodifysituation adaptee;
        zymodifysituation_jButton2_actionAdapter(zymodifysituation adaptee) {
            this.adaptee = adaptee;
        }

        public void actionPerformed(ActionEvent e) {
            adaptee.jButton2_actionPerformed(e);
        }
    }


        class zymodifysituation_jButton3_actionAdapter implements
                ActionListener {
            private zymodifysituation adaptee;
            zymodifysituation_jButton3_actionAdapter(zymodifysituation adaptee) {
                this.adaptee = adaptee;
            }

            public void actionPerformed(ActionEvent e) {
                adaptee.jButton3_actionPerformed(e);
            }
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -