Java课程设计-学籍信息管理系统

来源:互联网 发布:网络施工分成协议书 编辑:程序博客网 时间:2024/05/01 01:57

一、系统分析

        学生的学籍信息是记录学生的重要信息档案,如何以电子文档形式记录下学生的学籍信息是每个学校必须做的事情,该学生学籍信息管理系统就是为了方便学校记录下每一个学生的基本信息,生成电子数据库,并且能够做到查询、更改、删除、浏览等功能操作,让学籍信息的管理更加方便快捷。

二、设计方案

1、系统框架

        学籍信息管理系统是集学籍信息录入,学籍信息查询,学籍信息更改,学籍信息删除,学籍信息浏览这些功能模块于一体的信息管理系统。首先,需要管理员登陆到该系统,当用户名和密码均正确时方可进入系统。图2-1给出了学籍信息管理系统的系统结构图。


图2-1 系统结构图


学籍信息录入
该模块可以添加学生的基本信息(学号,姓名,性别,专业,班级,入学时间)。
学籍信息查询
该模块可以使用学号查询到以保存数据中某一个学生的信息。
学籍信息更改
该模块可以更改某一位学生的学号、姓名、性别、专业和入学时间。
学籍信息删除
该模块可以删除某一位学生的全部信息。
学籍信息浏览
该模块可以浏览全部学生的信息。

其中,学籍更改和浏览模块将另外生成两个新窗口,其他模块均在原有窗口上操作进行。

角色分析

学生类(Student)记录了学生的基本信息,该类的设计由图2-2所示,类的介绍如表2-1所示。


图2-2 学生的基本信息

 

表2-1 学生(Student.java)类的介绍

变量名称

类型

描述

number

String

学号

name

String

姓名

sex

String

性别

discipling

String

专业

grade

String

年级

borth

String

入学时间

 

三、算法分析

1、使用try和catch捕捉异常处理

Java通过5个关键字来控制异常处理,通常在出现错误时用try来执行代码,系统引发(throws)一个异常后,可以根据异常的类型由catch来捕获,或者用finally调用缺省异常处理。

在执行过程中,由try所指定的代码中的语句会生成异常对象并抛出。catch语句的参数类似于方法的声明,包括一个异常类型和异常对象。

 

try {inOne = new FileInputStream(file);inTwo = new ObjectInputStream(inOne);StudentDB = (Hashtable) inTwo.readObject();inOne.close();inTwo.close();} catch (Exception ee) {}


2、对象序列化

在Java.io包中,提供了ObjectInputStream和ObjectOutputStream,将数据流功能扩展至可读写对象。在ObjectInputStream中用readObject()方法可以直接读取一个对象,在ObjectOutputStream中用writeObject()方法可以直接将对象保存到输出流中。

inOne = new FileInputStream(file);inTwo = new ObjectInputStream(inOne);outOne = new FileOutputStream(file);outTwo = new ObjectOutputStream(outOne);

3、数据存储使用散列表

散列表根据关键码直接访问表,把关键码映射到表中的记录来访问记录,这个过程成为散列,散列方法不同于顺序查找、二分查找。它不以关键字的比较为基本操作,采用直接寻址技术。在理想情况下,无须任何比较就可以找到待查关键字,查找的期望时间为O(1)。
散列表上的运算有查找、插入和删除。其中主要是查找,这是因为散列表的目的主要是用于快速查找,且插入和删除均要用到查找操作。

Hashtable StudentDB = null;StudentDB = (Hashtable) inTwo.readObject();Student stu = (Student) StudentDB.get(number);

四、软件实现

1、代码组织

本系统由8个Java类、2张图片文件组成,其中,src存放了8个Java类,res存放的是管理员登陆时的图片(login.jpg)和主框架的图片(home.jpg)。类之间的关系如图4-1所示。

图4-1 该系统类关系图


各类的主要功能如表4-1所示。

表4-1 类功能介绍表

序号

类名

功能描述

1

Student.java

创建并存放学生类的对象

2

StudentInput.java

新学籍信息的录入

3

StudentInquire.java

学籍信息的查询界面

4

StudentChange.java

学籍信息的更改

5

StudentDelete.java

学籍信息的删除

6

StudentLogin.java

管理员登陆窗口,包含main函数

7

StudentTable.java

浏览全部的学籍信息

8

StudentFrame.java

学籍信息管理系统的主框架

 


2、详细设计

成员变量

1.      管理员登陆窗口(StudentLogin.java)如表4-2所示。

表4-2 管理员登陆窗口类成员变量表

变量名称

变量类型

描述

login,reset

JButton

登录、重置按钮

Username,password

JTextField

用户名、密码输入框

a,b

JLabel

提示语

word

JLabel

图片显示

 

 

2.      学籍管理系统主框架(StudentFrame.java) 如表4-3所示。

表4-3 学籍管理系统主框架类成员变量表

变量名称

变量类型

描述

input

StudentInput

构建学籍录入界面

change

StudenChange

构建学籍信息更改界面

inquire

StudentInquire

构建学籍信息查询界面

delete

StudentDelete

构建学籍信息删除界面

table

StudentTable

构建学籍信息浏览界面

bar

JMenuBar

创建一个菜单栏

fileMenu,editMenu,helpMenu

JMenu

创建一级菜单

input_1,change_1,inquire_1,

delete_1,about_1,exit_1,

table_1

JMenuItem

创建录入,更改,查询,删除,浏览,关于,退出子菜单

StudentDB

Hashtable

存放学生信息的散列表

file

File

存放学生信息的散列表文件

 

 

3.      学籍信息录入(StudentInput.java) 如表4-4所示。

表4-4 学籍信息录入类成员变量表

变量名称

变量类型

描述

StudentDB

Hashtable

存放学生信息的散列表

Snumber,Sname,Sspec,

Sclass,Sborth

JTxetField

学号,姓名,专业,班级,入学时间输入框

Sinput,Sreset

JButton

录入,重置按钮

Sman,Swomen

JRadioButton

男、女选项

file

File

存放学生信息的散列表文件

inOne

FileInputStream

从文件读取数据

inTwo

ObjectInputStream

将数据流功能扩展到可读写数据

outOne

FileOutputStream

向文件写入数据

outTwo

ObjectOutputStream

将数据流功能扩展到可读写数据

 

 

4.      学籍信息查询(StudentIquire.java)如表4-5所示。

表4-5 学籍信息查询类成员变量表

变量名称

变量类型

描述

StudentDB

Hashtable

存放学生信息的散列表

Snumber,Sname,Sspec,

Sclass,Sborth

JTxetField

学号,姓名,专业,班级,入学时间输入框

Sinquiry

JButton

查询按钮

Sman,Swomen

JRadioButton

男、女选项

file

File

存放学生信息的散列表文件

inOne

FileInputStream

从文件读取数据

inTwo

ObjectInputStream

将数据流功能扩展到可读写数据

 

 

5.学籍信息更改(StudentChange.java)如表4-6所示。

表4-6 学籍信息更改类成员变量表

变量名称

变量类型

描述

StudentDB

Hashtable

存放学生信息的散列表

Snumber,Sname,Sspec,

Sclass,Sborth

JTxetField

学号,姓名,专业,班级,入学时间输入框

Schange,Sreset,Sinquire

JButton

更改,查找,重置按钮

Sman,Swomen

JRadioButton

男、女选项

file

File

存放学生信息的散列表文件

inOne

FileInputStream

从文件读取数据

inTwo

ObjectInputStream

将数据流功能扩展到可读写数据

outOne

FileOutputStream

向文件写入数据

outTwo

ObjectOutputStream

将数据流功能扩展到可读写数据

 

 

6.学籍信息删除(StudentDelete.java)如表4-7所示。

表4-7 学籍信息删除类成员变量表

变量名称

变量类型

描述

StudentDB

Hashtable

存放学生信息的散列表

Snumber,Sname,Sspec,

Sclass,Sborth

JTxetField

学号,姓名,专业,班级,入学时间输入框

Sdelete,Sinquire

JButton

查找,删除按钮

Sman,Swomen

JRadioButton

男、女选项

file

File

存放学生信息的散列表文件

inOne

FileInputStream

从文件读取数据

inTwo

ObjectInputStream

将数据流功能扩展到可读写数据

outOne

FileOutputStream

向文件写入数据

outTwo

ObjectOutputStream

将数据流功能扩展到可读写数据

 

 

7.学籍信息浏览(StudentTable.java)如表4-8所示。

表4-8 学籍信息浏览类成员变量表

变量名称

变量类型

描述

stutable

JTable

创建一个学生表格

Snumber,Sname,Sspec,

Sclass,Sborth,Ssex

String

学号,姓名,专业,班级,入学时间字符串

Schange,Sreset,Sinquire

JButton

更改,查找,重置按钮

Sman,Swomen

JRadioButton

男、女选项

file

File

存放学生信息的散列表文件

inOne

FileInputStream

从文件读取数据

inTwo

ObjectInputStream

将数据流功能扩展到可读写数据

allinf,tablehead,line1

Vector

创建向量,将信息存入向量

jsp

JScrollPane

添加一个滚动条

 

 

主要方法

 

学生类(Student.java)如表4-9所示。

表4-9 学生类介绍表

名称

功能

setNumber

设置学号

setName

设置姓名

setSex

设置性别

setDisciping

设置专业

setGrade

设置班级

setBorth

设置入学时间

getNumber

获得学号

getName

获得姓名

getSex

获得性别

getDisciping

获得专业

getGrade

获得班级

getBorth

获得入学时间

 

 

其他类如表4-10所示。

表4-10 其他类介绍表

名称

功能

备注

actionPerformed

处理ActionEvent监听事件

接口方式,内部函数

input

创建录入界面

构造函数

change

创建更改界面

构造函数

inquire

创建查询界面

构造函数

delete

创建删除界面

构造函数

table

创建表格界面

构造函数

 

五、软件测试与使用

1-1管理员登陆界面(图5-1、5-2)

  

   


                                         图5-1管理员登陆界面                           图5-2管理员登陆界面

 

1-2系统主框架(图5-3)

 

图5-3系统主框架

 

1-3菜单栏(图5-4)

 

 

图5-4菜单栏

 

1-4录入界面(图5-5、5-6)

 

 

图5-5录入界面

 

 

图5-6 提示页面

 

 

1-5更改界面(图5-7、5-8)

 

 

图5-7更改界面

 

 

图5-8 提示界面

 

 

1-6查询界面(图5-9)

 

 

图5-9查询界面

 

1-7删除界面(图5-10、5-11)

 

 

图5-10删除界面

 

 

图5-11 提示界面

 

1-8浏览界面(图5-12)

 

 

图5-12浏览界面

 

 

六、参考文献及资料

《Introduction to java programming》 作者:Y.Daniel Liang 机械工业出版社
《java程序设计经典课堂》 作者:金松河、王捷、黄永丽 清华大学出版社

七、总结与体会

这是一个花了将近一周的时间才完成的项目,很惭愧的是平时不像大一那样每天都会写些代码所以导致对于Java显得那么的陌生。开始看了老师发给我们的视频,看完之后只有一个感觉,难!平时三星题做了三道了,按照老师的说法是在做两道就可以将三星题当成课程设计了,后来还是想自我挑战一下没有继续验收三星题,当我真的开始做项目的时候,才发现自己还是想的太简单了。平时练得少,程序算法先不说,光是一堆堆的类及其功能就不得而知,看了老师的视频,从网上找了一些源代码,他们都是使用了数据库和网络知识。然而我对数据库只是略懂一二,根本看不懂他们在写的是什么,随后,我还是下定决心自己写一份简单的吧。
从图书馆接了一本书(参考文献的第二本),基本的控制台还能够运行,但是GUI的就不顺畅了,从布局开始开始根据想要的功能进行慢慢的累加,就这样,懂得了几种布局方式,BorderLayout,GridLayout,CardLayout,Box等等,并一一进行了使用,后来知道了一种Eclipse的插件—Windows Builder,这种插件可以让java的GUI设计和VB相似,方便了很多。
过程中最大的困难是数据的存储和读取,大部分的程序都是使用的数据库,然而我的电脑都没有配置数据库环境,所以放弃了数据库的是使用。后来从网上找个了一种方式,利用散列表来进行存储,利用类的子对象containsKey(number)进行直接查找。经测试这种方式还不错,所以就采用了这种方式。每一个类中进行读取,查找。
后来就是功能的设计了,本程序一共5个子模块,尽管很简单,但还是费了一番周折,可见对于java我还是不熟练。经过这次课程设计,使我受益匪浅,感觉这一周的练习比一个学期掌握的知识还要多。并且及时的复习和稳固的这一学期所学的知识,也让课本的只是做到了融会贯通,看来理论和实践结合的方式才是学习最有效的方法,只有这样才能提高自己的编程技巧。

附录

部分源代码

StudentFrame.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.net.URL;import java.util.Hashtable;public class StudentFrame extends JFrame implements ActionListener {StudentInput input = null;StudentChange change = null;StudentInquire inquire = null;StudentDelete delete = null;StudentTable table = null;JMenuBar bar;JMenu fileMenu;JMenu editMenu;JMenu helpMenu;JMenuItem exit_1;// 退出菜单JMenuItem input_1, change_1, inquire_1, delete_1, table_1;JMenuItem about_1;// 关于菜单Container con = null;Hashtable StudentDB = null;File file = null;CardLayout card = null;JLabel label = null;JPanel pCenter;public StudentFrame() {exit_1 = new JMenuItem("退出");input_1 = new JMenuItem("学籍信息录入");change_1 = new JMenuItem("学籍信息更改");inquire_1 = new JMenuItem("学籍信息查询");delete_1 = new JMenuItem("学籍信息删除");table_1 = new JMenuItem("学籍信息浏览");about_1 = new JMenuItem("关于");bar = new JMenuBar();fileMenu = new JMenu("文件(F)");fileMenu.setMnemonic(KeyEvent.VK_F);// 添加助记键fileMenu.add(exit_1);editMenu = new JMenu("编辑(E)");editMenu.setMnemonic(KeyEvent.VK_E);editMenu.add(input_1);editMenu.add(change_1);editMenu.add(inquire_1);editMenu.add(delete_1);editMenu.add(table_1);helpMenu = new JMenu("帮助(H)");helpMenu.setMnemonic(KeyEvent.VK_H);helpMenu.add(about_1);bar.add(fileMenu);bar.add(editMenu);bar.add(helpMenu);this.setJMenuBar(bar);label = new JLabel("", JLabel.CENTER);// 显示图片的labellabel.setForeground(Color.black);StudentDB = new Hashtable();input_1.addActionListener(this);change_1.addActionListener(this);inquire_1.addActionListener(this);delete_1.addActionListener(this);table_1.addActionListener(this);exit_1.addActionListener(this);about_1.addActionListener(this);card = new CardLayout();con = getContentPane();pCenter = new JPanel();pCenter.setLayout(card);file = new File("StudentDB.dat");this.setTitle("学籍信息管理系统");if (!file.exists()) {try {FileOutputStream out = new FileOutputStream(file);ObjectOutputStream objectOut = new ObjectOutputStream(out);objectOut.writeObject(StudentDB);objectOut.close();out.close();} catch (IOException e) {}}input = new StudentInput(file);change = new StudentChange(file);inquire = new StudentInquire(this, file);delete = new StudentDelete(file);        table =new StudentTable(file);label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/home.jpg")));// 显示图片pCenter.add("主框架", label);pCenter.add("学籍录入", input);pCenter.add("学籍更改", change);pCenter.add("学籍删除", delete);con.add(pCenter, BorderLayout.CENTER);con.validate();addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});setVisible(true);setBounds(100, 50, 450, 400);setLocationRelativeTo(null);// 居中显示validate();}public void actionPerformed(ActionEvent e) {if (e.getSource() == input_1) {card.show(pCenter, "学籍录入");} else if (e.getSource() == change_1) {card.show(pCenter, "学籍更改");} else if (e.getSource() == inquire_1) {inquire.setVisible(true);} else if (e.getSource() == table_1) {table.setVisible(true);} else if (e.getSource() == delete_1) {card.show(pCenter, "学籍删除");} else if (e.getSource() == exit_1) {int ok = JOptionPane.showConfirmDialog(this, "确认退出该系统?", "退出系统", JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);if (ok == JOptionPane.YES_OPTION) {System.exit(0);}} else if (e.getSource() == about_1) {JOptionPane.showMessageDialog(null, "学籍信息管理系统V1.0", "关于", JOptionPane.INFORMATION_MESSAGE);}}}StudentInput.javaimport java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class StudentLogin extends JFrame implements ActionListener {private JPasswordField password;private JTextField username;private JButton login;private JButton reset;String name_1 = null, pass_1 = null;public StudentLogin() {this.setTitle("登录系统");Container container = this.getContentPane();container.setLayout(new FlowLayout());username = new JTextField(10);password = new JPasswordField(10);login = new JButton("登录");reset = new JButton("重置");login.addActionListener(this);reset.addActionListener(new ButtonEventHandle_1());JLabel a = new JLabel("用户名:");JLabel b = new JLabel("密码:");JLabel word = new JLabel("");JPanel admin = new JPanel();JPanel pass = new JPanel();JPanel butt = new JPanel();word.setIcon(new javax.swing.ImageIcon(getClass().getResource("/login.jpg")));// 显示图片admin.add(a);admin.add(username);pass.add(b);pass.add(password);butt.add(login);butt.add(reset);container.add(word, BorderLayout.NORTH);container.add(admin);container.add(pass);container.add(butt, BorderLayout.SOUTH);this.setVisible(true);this.setSize(300, 260);this.setLocationRelativeTo(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e) {char[] pswd = password.getPassword();String s_0 = new String(pswd);String user = username.getText();if (user.equals("admin") && s_0.equals("123456")) {JOptionPane.showMessageDialog(null, "登陆成功!");this.setVisible(false);new StudentFrame();} else if (user.equals("") || s_0.equals("")) {JOptionPane.showMessageDialog(null, "请输入用户名或密码!");} else {JOptionPane.showMessageDialog(null, "用户名或密码错误!");}}class ButtonEventHandle_1 implements ActionListener {public void actionPerformed(ActionEvent e) {username.setText(null);password.setText(null);}}public static void main(String[] args) {new StudentLogin();}}StudentTable.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class StudentTable extends JFrame {Hashtable StudentDB = null;String Snumber="1001", Sname, Sspec, Sclass, Sborth;String Ssex;JButton Sinquiry;ButtonGroup group = null;FileInputStream inOne = null;ObjectInputStream inTwo = null;File file = null;int i=1001;JTable stutable;public StudentTable(File file) {this.file = file;Vector allinf = new Vector();Vector tablehead = new Vector();// 表头信息tablehead.add("学号");tablehead.add("姓名");tablehead.add("性别");tablehead.add("专业");tablehead.add("班级");tablehead.add("入学时间");stutable = new JTable(allinf, tablehead);stutable.setEnabled(false);stutable.setPreferredScrollableViewportSize(new Dimension(0, 120));JScrollPane jsp = new JScrollPane();jsp.setViewportView(stutable);add(BorderLayout.CENTER, jsp);// 查找数据try {inOne = new FileInputStream(file);inTwo = new ObjectInputStream(inOne);StudentDB = (Hashtable) inTwo.readObject();inOne.close();inTwo.close();} catch (Exception ee) {}while((i-1001)<1000){Snumber = Integer.toString(i);if (StudentDB.containsKey(Snumber)) {Student stu = (Student) StudentDB.get(Snumber);Vector line1 = new Vector();// 存放信息的向量line1.add(stu.getNumber());line1.add(stu.getName());line1.add(stu.getSex());line1.add(stu.getDisciping());line1.add(stu.getGrade());line1.add(stu.getBorth());allinf.add(line1);} else {break;}i++;}validate();// 刷新窗口this.setVisible(false);this.setSize(600, 300);this.setTitle("学籍信息浏览");this.setLocationRelativeTo(null);// 居中显示addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {setVisible(false);}});}}StudentInquiry.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class StudentInquire extends JDialog implements ActionListener {Hashtable StudentDB = null;JTextField Snumber, Sname, Sspec, Sclass, Sborth;JRadioButton Sman, Swomen;JButton Sinquiry;ButtonGroup group = null;FileInputStream inOne = null;ObjectInputStream inTwo = null;File file = null;public StudentInquire(JFrame f, File file) {super(f, "学籍信息查询", false);this.file = file;Snumber = new JTextField(10);Sinquiry = new JButton("查询");Snumber.addActionListener(this);Sinquiry.addActionListener(this);Sname = new JTextField(10);Sname.setEditable(false);Sspec = new JTextField(10);Sspec.setEditable(false);Sclass = new JTextField(10);Sclass.setEditable(false);Sborth = new JTextField(10);Sborth.setEditable(false);Sman = new JRadioButton("男", false);Swomen = new JRadioButton("女", false);group = new ButtonGroup();group.add(Sman);group.add(Swomen);Box box1 = Box.createHorizontalBox();box1.add(new JLabel("请输入要查询学生的学号:", JLabel.CENTER));box1.add(Snumber);box1.add(Sinquiry);Box box2 = Box.createHorizontalBox();box2.add(new JLabel("姓名:", JLabel.CENTER));box2.add(Sname);Box box3 = Box.createHorizontalBox();box3.add(new JLabel("性别:", JLabel.CENTER));box3.add(Sman);box3.add(Swomen);Box box4 = Box.createHorizontalBox();box4.add(new JLabel("专业:", JLabel.CENTER));box4.add(Sspec);Box box5 = Box.createHorizontalBox();box5.add(new JLabel("班级:", JLabel.CENTER));box5.add(Sclass);Box box6 = Box.createHorizontalBox();box6.add(new JLabel("入学时间:", JLabel.CENTER));box6.add(Sborth);Box boxH = Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(box3);boxH.add(box4);boxH.add(box5);boxH.add(box6);boxH.add(Box.createVerticalGlue());JPanel pCenter = new JPanel();pCenter.add(boxH);Container con = getContentPane();con.add(pCenter, BorderLayout.CENTER);con.validate();setVisible(false);setBounds(100, 200, 360, 270);setLocationRelativeTo(null);// 居中显示addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {setVisible(false);}});}public void actionPerformed(ActionEvent e) {Sname.setText(null);Sspec.setText(null);Sclass.setText(null);Sborth.setText(null);if (e.getSource() == Sinquiry || e.getSource() == Snumber) {String number = "";number = Snumber.getText();if (number.length() > 0) {try {inOne = new FileInputStream(file);inTwo = new ObjectInputStream(inOne);StudentDB = (Hashtable) inTwo.readObject();inOne.close();inTwo.close();} catch (Exception ee) {}if (StudentDB.containsKey(number)) {Student stu = (Student) StudentDB.get(number);Sname.setText(stu.getName());Sspec.setText(stu.getDisciping());Sclass.setText(stu.getGrade());Sborth.setText(stu.getBorth());if (stu.getSex().equals("男")) {Sman.setSelected(true);} else {Swomen.setSelected(true);}} else {String warning = "没有该学号" + Snumber.getText() + "的学籍信息!";JOptionPane.showMessageDialog(this, warning, "警告", JOptionPane.WARNING_MESSAGE);}} else {String warning = "请输入学号!";JOptionPane.showMessageDialog(this, warning, "警告", JOptionPane.WARNING_MESSAGE);}}}} 


1 0
原创粉丝点击