面向对象程序综合设计课程设计(团队博客)

 

一.项目介绍

题目要求:

功能要求(1)

需要管理的学生信息有:学号,姓名,性别,出生日期,政治面貌,家庭住址,电话,宿舍号

(2)实现查询,增,删,改等功能。

数据存储:文件或数据库

Git地址:https://gitee.com/gxwen/122

一.团队成员

组长:李康

组员:高方,黄光宇,郭晓文

二.概要设计

                 

 

 

 

 

三.项目运行截图

用户注册页面

 

 

登入界面

 

功能选择界面

 

 

删除信息界面

 

 

 

 

 

 

 

 

 

添加学生信息界面

 

 

 

 

 

 

修改学生信息界面

 

 

 

 

 

 

 

 

展示所有学生信息界面

 

 

四.关键代码

 

   增加学生信息代码

   private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        new MainFrame().setVisible(true);

        this.setVisible(false);

    }                                        

 

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        String mes = null;

        String name = jTextField1.getText();

        String stuno = jTextField2.getText();

        Object source = evt.getSource();

String gender = "...",statu = "...";

if(source == jButton1)

{

if(jRadioButton6.isSelected() == true) gender = jRadioButton6.getText();

if(jRadioButton1.isSelected() == true) gender = jRadioButton1.getText();

if(jRadioButton2.isSelected() == true) statu = jRadioButton2.getText();

if(jRadioButton3.isSelected() == true) statu = jRadioButton3.getText();

if(jRadioButton4.isSelected() == true) statu = jRadioButton4.getText();

        String tel = jTextField3.getText();

        String birthday = jTextField4.getText();

        String[] databirthday = birthday.split("/");

        int year = Integer.parseInt(databirthday[0]);

        int month = Integer.parseInt(databirthday[1]);

        int day = Integer.parseInt(databirthday[2]);

        if (year>=2017&&year<=1900){

            mes = "错误提示:出生日期格式错误、";  

        }else{

            if (month<0&&month>13){

                mes = "错误提示:出生日期格式错误、";      

            }else{

                if (day>31&&day<0) mes =  "错误提示:出生日期格式错误、";

            }

        }

        for(int i=0;i<txt.size();i++){//判别这个学号是否已经存在

         String detail = txt.get(i);

         String[] detaildata = detail.split(",");

         if (stuno.equals(detaildata[0])){

         mes = "错误提示:该学号已经存在,你可以选择更改学号或者修改学生信息!!!";

         }

        }

        String roomnum = jTextField5.getText();

        String address = jTextField6.getText();

        if(name == null||stuno == null||tel == null||roomnum == null||gender.equals("...")||statu.equals("...")||birthday == null) {

         mes = mes + "错误提示:信息不能为空请重新输入!!!";

         jLabel10.setText(mes);

         return;

        }

String msg = stuno+","+name+","+gender+","+databirthday[0]+"-"+databirthday[1]+"-"+databirthday[2]

+","+statu+","+address+","+tel+","+roomnum;

txt.add(msg);//添加新的数据加入

Collections.sort(txt);

try {

PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("Student.txt")));

for(int i = 0; i<txt.size();i++){

pw.println(txt.get(i));

pw.flush();//刷新printwriter缓冲区

}

pw.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

}

new AddFrame().setVisible(true);

        this.setVisible(false);

}

    }   

 

修改学生信息代码

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        String data = jTextField1.getText();

        Object source = evt.getSource();

        if(source == jButton1)

        {

            if(jRadioButton1.isSelected() == true) {//如果选择了学号按钮

                for(int i = 0 ; i < txt.size() ; i++ ){//学号查询

                    String detail = txt.get(i);//获得字符串即学生信息

                    String[] detaildata = detail.split(",");

                    if(data.equals(detaildata[0])){

                     jTextField3.setText(detaildata[0]);//学号

                        jTextField2.setText(detaildata[1]);//姓名

                        jTextField5.setText(detaildata[2]);//性别

                        jTextField7.setText(detaildata[3]);//出生日期

                        jTextField9.setText(detaildata[4]);//政治面貌

                        jTextField6.setText(detaildata[5]);//家庭住址

                        jTextField4.setText(detaildata[6]);//电话

                        jTextField8.setText(detaildata[7]);//宿舍号

                        break;

                    }

                }

            }

            if(jRadioButton2.isSelected() == true){

                for(int i = 0 ; i < txt.size() ; i++ ){//姓名查询

                    String detail = txt.get(i);//获得字符串即学生信息

                    String[] detaildata = detail.split(",");

                    if(data.equals(detaildata[1])){

                     jTextField3.setText(detaildata[0]);//学号

                        jTextField2.setText(detaildata[1]);//姓名

                        jTextField5.setText(detaildata[2]);//性别

                        jTextField7.setText(detaildata[3]);//出生日期

                        jTextField9.setText(detaildata[4]);//政治面貌

                        jTextField6.setText(detaildata[5]);//家庭住址

                        jTextField4.setText(detaildata[6]);//电话

                        jTextField8.setText(detaildata[7]);//宿舍号

                        break;

                    }

                }

            }

        }

    }                                        

 

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

     String data = jTextField1.getText();

     String mes = null;

     String stuno = jTextField3.getText();//学号

     String name = jTextField2.getText();//姓名

     String gender = jTextField5.getText();//性别

     String birthday = jTextField7.getText();//出生日期

     String statu = jTextField9.getText();//政治面貌

     String address = jTextField6.getText();//家庭住址

     String tel = jTextField4.getText();//电话

     String roomnum = jTextField8.getText();//宿舍号

     String msg = stuno+","+name+","+gender+","+birthday+","+statu+","+

     address+","+tel+","+roomnum;

     for(int i = 0 ; i < txt.size() ; i++ ){//按学号修改

            String detail = txt.get(i);//获得字符串即学生信息

            String[] detaildata = detail.split(",");

            if(data.equals(detaildata[0])){

             txt.remove(i);

             txt.add(i, msg);            

                break;

            }

        }

     for(int i = 0 ; i < txt.size() ; i++ ){

            String detail = txt.get(i);//获得字符串即学生信息

            String[] detaildata = detail.split(",");

            if(data.equals(detaildata[0])){//按学号修改

             txt.remove(i);

             txt.add(i, msg);            

                break;

            }else if(data.equals(detaildata[1])){//按姓名修改

             txt.remove(i);

             txt.add(i, msg);            

                break;

            }            

        }        

mes = "已成功修改了 "+name+" 的信息";

 

删除学生信息代码

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

String mes = null;

     String data = jTextField1.getText();

        Object source = evt.getSource();

if(source == jButton1)

{

if(jRadioButton3.isSelected() == true) {//如果选择了学号按钮

for(int i = 0 ; i < txt.size() ; i++ ){//学号查询

String detail = txt.get(i);//获得字符串即学生信息

String[] detaildata = detail.split(",");

if(data.equals(detaildata[0])){

jLabel4.setText(detaildata[0]);//学号

jLabel6.setText(detaildata[1]);//姓名

jLabel8.setText(detaildata[2]);//性别

jLabel12.setText(detaildata[3]);//出生日期

jLabel14.setText(detaildata[4]);//政治面貌

jLabel10.setText(detaildata[6]);//电话

jLabel19.setText(detaildata[7]);//宿舍号

mes = "已经找到Ta...";

break;

}else{

mes = "无此人";

}

}

jLabel16.setText(mes);//添加错误提醒

}

if(jRadioButton2.isSelected() == true){

for(int i = 0 ; i < txt.size() ; i++ ){//姓名查询

String detail = txt.get(i);//获得字符串即学生信息

String[] detaildata = detail.split(",");

if(data.equals(detaildata[1])){

jLabel4.setText(detaildata[0]);//学号

jLabel6.setText(detaildata[1]);//姓名

jLabel8.setText(detaildata[2]);//性别

jLabel12.setText(detaildata[3]);//出生日期

jLabel14.setText(detaildata[4]);//政治面貌

jLabel10.setText(detaildata[6]);//电话

jLabel19.setText(detaildata[7]);//宿舍号

mes = "已经找到Ta...";

break;

}else{

mes = "无此人";

}

}

jLabel16.setText(mes);//添加错误提醒

}

}

    }                                        

 

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        new MainFrame().setVisible(true);

        this.setVisible(false);

    }                                        

 

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        new ChangeFrame().setVisible(true);

        this.setVisible(false);

    }                                        

 

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        new DisplayFrame().setVisible(true);

 

    }                                        

 

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        System.exit(0);

    }                                        

 

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        new AddFrame().setVisible(true);

        this.setVisible(false);

    }                                        

 

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        new SearchFrame().setVisible(true);

        this.setVisible(false);

    }                                        

 

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

     String mes = null;

     String data = jTextField1.getText();

     if(jRadioButton3.isSelected() == true) {//如果选择了学号按钮

for(int i = 0 ; i < txt.size() ; i++ ){//学号查询

String detail = txt.get(i);//获得字符串即学生信息

String[] detaildata = detail.split(",");

if(data.equals(detaildata[0])){

txt.remove(i);

mes = "已成功删除"+detaildata[1]+"的信息!!!";

break;

}else if(data.equals(detaildata[1])){

txt.remove(i);

mes = "已成功删除"+detaildata[1]+"的信息!!!";

break;

}

}

jLabel16.setText(mes);//添加提醒

try {

PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("Student.txt")));

for(int i = 0; i<txt.size();i++){

pw.println(txt.get(i));

pw.flush();//刷新printwriter缓冲区

}

pw.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

}

}

 

}  

五.测试与感想

从一开始的登入界面选择展示学生信息功能会出现乱码问题,一开始要先单独运行一下展示功能的代码然后就可以正常运行。预留一个未实现的功能,可在未来丰富系统功能。另外,这个系统本来应该有三种用户,为管理员,老师和学生,管理员可以修改学生信息,权限最高,老师可以浏览所有学生信息,学生可以查看自己的信息并修改。这个系统较简陋,只设置了管理员(教师)这一种用户。,可以再改进。

六.附带文件:完整,可运行代码

 

posted on 2019-01-18 13:41  FaithTowin  阅读(133)  评论(1编辑  收藏  举报

导航