代码改变世界

Java课程设计——学生基本信息管理

2017-06-23 08:39  花雨芸  阅读(1195)  评论(0编辑  收藏  举报

1.团队名称、团队成员介绍

团队名称:学生基本信息管理设计小组
团队成员:花雨芸(组长)——负责管理界面的编写
丁蓉(组员)——负责登陆的设计编写

2.项目git地址

https://git.oschina.net/TSlover/java201521123070.git

3. 项目git提交记录截图(要体现出每个人的提交记录、提交说明),老师将点击进去重点考核。

丁蓉

花雨芸

4.项目功能架构图与主要功能流程图

项目功能架构图:

主要功能流程图:

5.项目运行截图

登陆界面

管理界面

6.项目关键代码(不能太多)

1.登陆界面

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package StudentManageSystem;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;

/**
 *
 * @author C065
 */
public class Login extends javax.swing.JFrame {

	private javax.swing.JButton jb1;
    private javax.swing.JLabel jl1;
    private javax.swing.JLabel jl2;
    private javax.swing.JLabel JL;
    private javax.swing.JTextField dt1;
    private javax.swing.JPasswordField dt2;
    JFrame f = null;
	
    public Login() {
        initComponents();
        File file = new File("C://Login_user.txt");			
    	try{
    	    if(!file.exists())
    			file.createNewFile();
    	}catch(IOException e){
    		e.printStackTrace();
    	}
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

    	f = new JFrame("学生基本信息管理系统");
        JL = new javax.swing.JLabel();
        jb1 = new javax.swing.JButton();
        dt1 = new javax.swing.JTextField();
        dt2 = new javax.swing.JPasswordField();
        jl1 = new javax.swing.JLabel();
        jl2 = new javax.swing.JLabel();
                
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        JL.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        JL.setText("欢迎进入学生基本信息系统");

        jb1.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        jb1.setText("登录");
        jb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb1actionPerformed(evt);
            }
        });

        jl2.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
        jl2.setText("密码:");

        jl1.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
        jl1.setText("用户名:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(60, 60, 60)
                .addComponent(JL)
                .addContainerGap(94, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jl1, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                    .addComponent(jl2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jb1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(dt2)
                        .addComponent(dt1, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)))
                .addGap(74, 74, 74))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(JL, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jl1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dt1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dt2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jl2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(69, 69, 69)
                .addComponent(jb1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

	public void jb1actionPerformed(java.awt.event.ActionEvent evt) {
		// TODO Auto-generated method stub	
		String name;
		String psw;
		String line;
		boolean pass = false;
		
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("C://Login_user.txt.txt")));
			while((line = br.readLine()) != null){
				String[] str = line.split("#");
				name = str[0];
				psw = str[1];
				System.out.println(dt1.getText());
				System.out.println(dt2.getPassword());
				boolean flag = true;
				char[] tmp = dt2.getPassword();
				char[] cmp = psw.toCharArray();
				if (tmp.length != cmp.length) {
					flag = false;
				} else {
					for (int i = 0; i < Math.min(tmp.length, cmp.length); i++) {
						if (tmp[i] != cmp[i]) {
							flag = false;
							break;
						}
					}
				}
				
				if(dt1.getText().equals(name) && flag){
					pass = true;
					break;
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		if(pass){
			new Test();
			f.dispose();
		    
		} else {
			JOptionPane.showMessageDialog(null,"密码或账号错误","提示!",JOptionPane.YES_NO_OPTION);
		}
		    
		    dt1.setText("");
		    dt2.setText("");
	}	
    
    public static void main(String args[]) {
        
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Login().setVisible(true);
            }
        });
    }
                  
}

2.管理界面
(1)增加

    class InputAct implements ActionListener{
        public void actionPerformed(ActionEvent e){
           修改.setEnabled(false);
           String number="";
           number=学号.getText();
          if(number.length()>0){
              try{
                  inOne=new FileInputStream(file);
                  inTwo=new ObjectInputStream(inOne);
                  学生散列表=(Hashtable)inTwo.readObject();
                  inOne.close();
                  inTwo.close();
              }
              catch(Exception ee){System.out.println("创建散列表出现问题!");}
              if(学生散列表.containsKey(number)){
                  String warning="该生信息已存在,请到修改页面修改!";
                  JOptionPane.showMessageDialog(null,warning,"警告",
                          JOptionPane.WARNING_MESSAGE);
              }//end if1
              else{
                  String m="该生信息将被录入!";
                  int ok=JOptionPane.showConfirmDialog(null,m,"确认",
                          JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
                  if(ok==JOptionPane.YES_OPTION){
                      String name=姓名.getText();
                      String specialty=出生.getText();
                      String politics=政治面貌.getText();
                      String borth=出生.getText();
                      String address=家庭住址.getText();
                      String phone=电话.getText();
                      String dormitory=宿舍号.getText();
                      String sex=null;
                      if(男.isSelected()){sex=男.getText();}
                      else{sex=女.getText();}
                      学生=new Student();
                      学生.setNumber(number);
                      学生.setName(name);
                      学生.setBorth(borth);
                      学生.setPolitics(politics);
                      学生.setAddress(address);
                      学生.setPhone(phone);
                      学生.setDormitory(dormitory);

                      学生.setSex(sex);
                      try{
                          outOne=new FileOutputStream(file);
                          outTwo=new ObjectOutputStream(outOne);
                          学生散列表.put(number,学生);
                          outTwo.writeObject(学生散列表);
                          outTwo.close();
                          outOne.close();
                      }
                      catch(Exception ee){System.out.println("输出散列表出现问题!");}
                      学号.setText(null);
                      姓名.setText(null);
                      出生.setText(null);
                      政治面貌.setText(null);
                      家庭住址.setText(null);
                      电话.setText(null);
                      宿舍号.setText(null);
                  }
              }//end else1
          }//end if0
          else{
              String warning="必须输入学号!";
              JOptionPane.showMessageDialog(null,warning,
                      "警告",JOptionPane.WARNING_MESSAGE);
          }//end else0
      }//end actionPerformed
    }//end class

(2)查询

    class InquestAct implements ActionListener{
        public void actionPerformed(ActionEvent e){
           String number="";
           number=学号.getText();
          if(number.length()>0){
              try{
                  inOne=new FileInputStream(file);
                  inTwo=new ObjectInputStream(inOne);
                  学生散列表=(Hashtable)inTwo.readObject();
                  inOne.close();
                  inTwo.close();
              }
              catch(Exception ee){System.out.println("散列表有问题!");}
              if(学生散列表.containsKey(number)){
                修改.setEnabled(true);
                Student stu=(Student)学生散列表.get(number);
                姓名.setText(stu.getName());
                出生.setText(stu.getBorth());
                政治面貌.setText(stu.getPolitics());
                家庭住址.setText(stu.getAddress());
                电话.setText(stu.getPhone());
                宿舍号.setText(stu.getDormitory());
                if(stu.getSex().equals("男")){男.setSelected(true);}
                else{女.setSelected(true);}
              }
              else{
                  修改.setEnabled(false);
                  String warning="该学号不存在!";
              JOptionPane.showMessageDialog(null,warning,
                      "警告",JOptionPane.WARNING_MESSAGE);
              }
          }
          else{
          修改.setEnabled(false);
          String warning="必须输入学号!";
              JOptionPane.showMessageDialog(null,warning,
                      "警告",JOptionPane.WARNING_MESSAGE);
          }
        }
    }

(3)修改

    class ModifyAct implements ActionListener{
       public void actionPerformed(ActionEvent e){
           String number=学号.getText();
           String name=姓名.getText();
           String borth=出生.getText();
           String politics=政治面貌.getText();
           String address=家庭住址.getText();
           String phone=电话.getText();
           String dormitory=宿舍号.getText();
           String sex=null;
           if(男.isSelected()){sex=男.getText();}
           else{sex=女.getText();}
           Student 学生=new Student();
           学生.setNumber(number);
           学生.setName(name);
           学生.setBorth(borth);
           学生.setPolitics(politics);
           学生.setAddress(address);
           学生.setPhone(phone);
           学生.setDormitory(dormitory);
           学生.setSex(sex);
           try{
               outOne=new FileOutputStream(file);
               outTwo=new ObjectOutputStream(outOne);
               学生散列表.put(number, 学生);
               outTwo.writeObject(学生散列表);
               outTwo.close();
               outOne.close();
               学号.setText(null);
               姓名.setText(null);
               出生.setText(null);
               政治面貌.setText(null);
               家庭住址.setText(null);
               电话.setText(null);
               宿舍号.setText(null);
           }
           catch(Exception ee){
               System.out.println("录入修改出现异常!");
               修改.setEnabled(false);
           }
       }
   }

(4)删除

   class DeleteAct implements ActionListener{
       public void actionPerformed(ActionEvent e){
           修改.setEnabled(false);
           String number=学号.getText();
          if(number.length()>0){
              try{
                  inOne=new FileInputStream(file);
                  inTwo=new ObjectInputStream(inOne);
                  学生散列表=(Hashtable)inTwo.readObject();
                  inOne.close();
                  inTwo.close();
              }
              catch(Exception ee){}
              if(学生散列表.containsKey(number)){
                Student stu=(Student)学生散列表.get(number);
                姓名.setText(stu.getName());
                出生.setText(stu.getBorth());
                政治面貌.setText(stu.getPolitics());
                家庭住址.setText(stu.getAddress());
                电话.setText(stu.getPhone());
                宿舍号.setText(stu.getDormitory());
                if(stu.getSex().equals("男")){男.setSelected(true);}
                else{女.setSelected(true);}
              }
              String m="确定要删除该学生的记录吗?";
              int ok=JOptionPane.showConfirmDialog(null,m,"确认",
                 JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
              if(ok==JOptionPane.YES_OPTION){
                  学生散列表.remove(number);
                  try{
                      outOne=new FileOutputStream(file);
                      outTwo=new ObjectOutputStream(outOne);
                      outTwo.writeObject(学生散列表);
                      outTwo.close();
                      outOne.close();
                      学号.setText(null);
                      姓名.setText(null);
                      出生.setText(null);
                      政治面貌.setText(null);
                      家庭住址.setText(null);
                      电话.setText(null);
                      宿舍号.setText(null);
                  }
                  catch(Exception ee){System.out.println(ee);}

              }
              else if(ok==JOptionPane.NO_OPTION){
                  学号.setText(null);
                  姓名.setText(null);
                  出生.setText(null);
                  政治面貌.setText(null);
                  家庭住址.setText(null);
                  电话.setText(null);
                  宿舍号.setText(null);
              }
              else{
                  String warning="该学号不存在!";
                  JOptionPane.showMessageDialog(null,warning,
                          "警告",JOptionPane.WARNING_MESSAGE);
              }
          }
          else{
               String warning="必须输入学号!";
               JOptionPane.showMessageDialog(null,warning,
                      "警告",JOptionPane.WARNING_MESSAGE);
          }
       }
   }

(5)查询

    class ShowAct implements ActionListener{
       public void actionPerformed(ActionEvent e){
           new StudentShow(file);
       }
    }
    class StudentShow extends JDialog{
       Hashtable 学生散列表= null;
       JTextArea 显示=null;
       FileInputStream inOne=null;
       ObjectInputStream inTwo=null;
       File file=null;
       public StudentShow(File file){
           super(new JFrame(),"显示对话框");
           this.file=file;
           显示=new JTextArea(16,30);
           try{
               inOne=new FileInputStream(file);
               inTwo=new ObjectInputStream(inOne);
               学生散列表=(Hashtable)inTwo.readObject();
               inOne.close();
               inTwo.close();
           }
           catch(Exception ee){}
           if(学生散列表.isEmpty())显示.append("目前还没有学生的信息记录!\n");
           else{
               显示.setText("学号 姓名 出生 政治面貌 家庭住址 电话 宿舍号\n");
               for(Enumeration enm=学生散列表.elements();enm.hasMoreElements();){
                   Student stu=(Student)enm.nextElement();
                   String sex="";
                   if(stu.getSex().equals("男"))sex="男";
                   else sex="女";
                   String str=stu.getNumber()+","+stu.getName()+","+sex+","
                 +stu.getBorth()+","+stu.getPolitics()+","+stu.getAddress()+","
                 +stu.getPhone()+","+stu.getDormitory()+"\n";
                   显示.append(str);
                   }
    }
           JScrollPane scroll=new JScrollPane(显示);
           Container con=getContentPane();
           con.add("Center",scroll);
           con.validate();
           setVisible(true);
           setBounds(200,200,400,300);
           addWindowListener(new WindowAdapter(){
               public void windowClosing(WindowEvent e){setVisible(false);}
               });
           }
     }

7. 尚待改进或者新的想法

1.界面不够美观;
2.功能不够完善和灵活;

8.团队成员任务分配,团队成员课程设计博客链接(以表格形式呈现),标明组长。

1.花雨芸(组长):http://www.cnblogs.com/hyy786030686/p/7063914.html
2.丁蓉: