Java课设(学生信息管理系统)
2017-06-22 11:09
561 查看
1.团队课程设计博客链接
http://www.cnblogs.com/Min21/p/7064093.html2.个人负责模板或任务说明
设计登陆界面和学生信息界面的设计,学生信息的显示、退出等功能。3.自己的代码提交记录截图
4.自己负责模块或任务详细说明
(一)总体设计(概要设计)
系统主要功能(1)需要管理的学生信息有:学号、姓名、性别、出生日期、政治面貌、家庭住址、电话、宿舍号。
(2)点清空按钮,数据将会清空。实际上它的作用就是清空输入栏。方便再往里面加入数据。
(3)查看功能:首先输入要查看的学号,点查看,信息将会显示在输入栏中。如果学号不存在,下面会有提示。
(4)修改功能:为了防止误修改,首先要查看,才能修改,查看后直接改输入栏中的数据,点击修改,既修改成功。
(5)删除功能:先输入要删除的学号,点删除,该学生的信息将被移除,在查看该学号,将不存在。
(6)显示功能:你输入的数据通过序列化保存在一个文档里,点击显示, 会跳出一个窗口,能把它们全部显示出来。
(7)系统退出:其实就是退出登录状态,返回登录界面。可以再重新登录。
数据存储:文件。
流程图:
(二)本人负责的主要功能展示与代码分析
(1)学生登陆界面。程序运行显示的第一个界面。输入用户名和密码就可以进入管理界面。
用户名:admin
密码:admin
用户名或密码错误会报错:
重置用于清空输入栏
主要代码:
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; class LoginCheck{ private String name; private String password; public LoginCheck(String name,String password){ this.name=name; this.password=password; } public boolean equals(){ if("admin".equals(name)&&"admin".equals(password)){ return true; }else{ return false; } } }; class ActionHandle{ private JFrame frame=new JFrame("学生信息管理系统"); private JTextField name=new JTextField();//设置文本框 private JPasswordField pass=new JPasswordField(); private JLabel but1=new JLabel("用户名:"); private JLabel but2=new JLabel("密 码:"); private JButton but3=new JButton("登陆"); private JButton but4=new JButton("重置"); public ActionHandle(){ but3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if(e.getSource()==but3){ String sname=name.getText(); String spass=new String(pass.getPassword()); LoginCheck log=new LoginCheck(sname,spass); if(log.equals()){ try { new Menu(); } catch (Exception e1) { e1.printStackTrace(); } frame.setVisible(false); }else{ JOptionPane.showMessageDialog(null, "登录失败,错误的用户名或密码!"); } } } }); but4.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ if(e.getSource()==but4){ name.setText(""); pass.setText(""); } } }); frame.setLayout(null); but1.setBounds(80, 40 , 80,30); name.setBounds(140,40, 120, 30); // but2.setBounds(80, 80 , 80,30); pass.setBounds(140,80, 120, 30); but3.setBounds(100, 150 , 60,30); but4.setBounds(180, 150 , 60,30); frame.setSize(400,330); frame.setLocation(300, 200); frame.add(but1); frame.add(name); frame.add(pass); frame.add(but2); frame.add(but3); frame.add(but4); frame.setVisible(true); } } public class Enter{ public static void main(String[] args) { new ActionHandle(); } }
(2)学生信息的显示、退出。
当输入学生信息后,信息保存到文件中,之后点击显示按钮,即可得到
如下图:
代码展示:
package Student; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Enumeration; import java.util.Hashtable; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; public class Menu { private JButton but1 = new JButton("增加数据"); // 按钮 private JButton but2 = new JButton("删除数据"); private JButton but3 = new JButton("修改数据"); private JButton but4 = new JButton("查看数据"); private JButton but0 = new JButton("系统退出"); private JButton but5 = new JButton("显示"); private JButton clear = new JButton("清空"); private JTextField number = new JTextField();// 文本框 private JTextField name = new JTextField(); private JTextField dor = new JTextField(); private JTextField address = new JTextField(); private JTextField sex = new JTextField(); private JTextField date = new JTextField(); private JTextField pol = new JTextField(); private JTextField phone = new JTextField(); private JTextArea show = new JTextArea(16, 30); private JLabel lab1 = new JLabel("姓名:");// 标签 private JLabel lab2 = new JLabel("宿舍号:"); private JLabel num = new JLabel("学号:"); private JLabel lab4 = new JLabel("家庭住址:"); private JLabel lab5 = new JLabel("性别:"); private JLabel lab6 = new JLabel("出生日期:"); private JLabel lab7 = new JLabel("政治面貌:"); private JLabel lab8 = new JLabel("电话:"); // private JLabel lab3 = new JLabel("请输入内容,完成操作。"); private JFrame frame = new JFrame("信息管理系统"); // 框架 private JFrame frame1 = new JFrame("显示信息"); Hashtable<String, Person> has = new Hashtable<String, Person>();// 哈希表,加密,文件乱码 File file = new File("学生信息.txt");// 新建一个文件 public Menu() { if (!file.exists()) { try { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));// 把一个实例的对象以文件的形式保存到磁盘上。 out.writeObject(has); out.close(); } catch (IOException e) { } } but5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() == but5) { frame1.setVisible(true); try { ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); has = (Hashtable) in.readObject(); in.close(); } catch (Exception ee) { } if (has.isEmpty()) { show.append("目前还没有学生的信息记录!\n"); // append(s:String)向文本域的文本追加字符串,简单的说就像system.out.println() } else { for (Enumeration enu = has.elements(); enu.hasMoreElements();) { //存入内存的内容如果不经过遍历是显示不出来的 Person per = (Person) enu.nextElement(); String str = " <学号>:" + per.getNum() + "\n" + " <姓名>:" + per.getName() + "\n" + " <宿舍号>:" + per.getDor() + "\n" + " <家庭住址>:" + per.getAddress() + "\n" + " <性别>:" + per.getSex() + "\n" + "<出生日期>:" + per.getDate() + "\n" + " <政治面貌>:" + per.getPol() + "\n" + " <电话>:" + per.getPhone() + "\n" + "\n"; show.append(str); } String str2 = "------------------------------结束---------------------------------------------------" + "\n"; show.append(str2); } } } }); but0.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() == but0) { frame.setVisible(false); new ActionHandle(); } } }); frame.setLayout(null); but1.setBounds(30, 35, 90, 25); but2.setBounds(30, 75, 90, 25); but3.setBounds(30, 115, 90, 25); but4.setBounds(30, 155, 90, 25); but0.setBounds(240, 430, 100, 25); // setBounds(x,y,width,height); num.setBounds(150, 30, 70, 25); lab1.setBounds(150, 65, 70, 25); lab2.setBounds(150, 100, 70, 25);// lab4.setBounds(150, 135, 70, 25); lab5.setBounds(150, 170, 70, 25); lab6.setBounds(150, 205, 70, 25); lab7.setBounds(150, 240, 70, 25); lab8.setBounds(150, 275, 70, 25); number.setBounds(230, 30, 90, 25); name.setBounds(230, 65, 90, 25); dor.setBounds(230, 100, 90, 25); address.setBounds(230, 135, 90, 25); sex.setBounds(230, 170, 90, 25); date.setBounds(230, 205, 90, 25); pol.setBounds(230, 240, 90, 25); phone.setBounds(230, 275, 90, 25); // lab3.setBounds(130, 390, 250, 25); clear.setBounds(250, 310, 60, 25); but5.setBounds(150, 310, 60, 25); frame.add(lab1); frame.add(lab2); //frame.add(lab3); frame.add(lab4); frame.add(lab5); frame.add(lab6); frame.add(lab7); frame.add(lab8); frame.add(num); frame.add(number); frame.add(name); frame.add(dor); frame.add(address); frame.add(sex); frame.add(date); frame.add(pol); frame.add(phone); frame.add(clear); frame.add(but1); frame.add(but2); frame.add(but3); frame.add(but4); frame.add(but0); JScrollPane scroll = new JScrollPane(show); frame1.add(scroll,BorderLayout.CENTER); frame.add(but5); frame.setSize(400, 500); // 页面大小 frame1.setBounds(200, 200, 400, 300); frame.setLocation(300, 200); frame.setVisible(true); frame1.setVisible(false); } }
5.课程设计感想
1.功能比较齐全,增删改查都有,虽然GUI设计得比较简陋。2.需要完善添加统计学生各门科目成绩,班级平均分等。
相关文章推荐
- java学生信息管理系统源代码
- 用java开发学生信息管理系统(SIMS,五)
- 学生信息管理系统--(Java+MySQL实现)
- Java+MySQL实现学生信息管理系统源码
- JAVA学生信息管理系统(数据库版)
- 用java开发学生信息管理系统(SIMS,一)
- Java练习 学生信息管理系统简版
- java学生信息管理系统设计(2)
- 自写的java学生信息管理系统
- 学生信息管理系统【JavaWeb】SSH+Mysql+Jsp
- java写的迷你学生信息管理系统
- Java写的学生信息管理系统
- java 学生信息管理系统
- JAVA学生信息管理系统
- 学生信息管理系统--java
- 用java开发学生信息管理系统(SIMS,四)
- Android(java)学习笔记195:学生信息管理系统案例(SQLite + ListView)
- 用java开发学生信息管理系统(SIMS,二)
- java学生信息管理系统设计
- java中用集合编写简单的学生信息管理系统