课程设计(论文)任务书
软 件 学 院 学院 软件工程 专业 10—3 班
一、课程设计(论文)题目 学籍管理系统 二、课程设计(论文)工作自 2011 年 12 月 12 日起至 2011 年 12 月 16 日止。 三、课程设计(论文) 地点: 软 件 学 院 实 训 中 心 四、课程设计(论文)内容要求: 1.本课程设计的目的
(1)掌握Java语言的程序设计方法;
(2)理论联系实际,进一步提高学生的软件开发技术; (3)培养学生分析、解决问题的能力; (4)提高学生实践论文撰写能力。 2.课程设计的任务及要求 1)课程设计任务:
基于学籍管理系统的程序设计: 1.录入学生基本信息的功能; 2.修改学生基本信息的功能; 3.查找学生基本信息的功能; 4.删除学生基本信息的功能; 2)创新要求:
基于文件流的插入与读取; 3)课程设计论文编写要求 (1)课程设计任务及要求
(2)设计思路--工作原理、功能规划
(3)详细设计---数据分析、算法思路、类设计、功能实现(含程序流程图、主要代
码及注释)、界面等。
(4)运行调试与分析讨论---给出运行屏幕截图,分析运行结果,有何改进想法等。 (5)设计体会与小结---设计遇到的问题及解决办法,通过设计学到了哪些新知识,
巩固了哪些知识,有哪些提高。
(6)参考文献(必须按标准格式列出,可参考教材后面的参考文献格式) (7)报告按规定排版打印,要求装订平整,否则要求返工;
华东交通大学课程设计报告
(8)课设报告的装订顺序如下:封面---任务书---中文摘要---目录----正文---附录
(代码及相关图片)
(9)严禁抄袭,如有发现,按不及格处理。 4)课程设计评分标准: (1)学习态度:20分; (2)程序检查:20分; (3)课设答辩:20分; (4)课设报告:40分。 5)参考文献:
(1)丁振凡. Java语言实用教程(第2版)[M]. 清华大学出版社. 2008.1
6)课程设计进度安排
1.准备阶段(4学时):选择设计题目、了解设计目的要求、查阅相关资料 2.程序模块设计分析阶段(4学时):程序总体设计、详细设计 3.代码编写调试阶段(8学时):程序模块代码编写、调试、测试
4.撰写论文阶段(4学时):总结课程设计任务和设计内容,撰写课程设计论文
学生签名:
2011 年 12 月 12 日
课程设计(论文)评审意见
(1)学习态度(20分):优( )、良( )、中( )、一般( )、差( ); (2)程序检查(20分):优( )、良( )、中( )、一般( )、差( ); (3)课设答辩(20分):优( )、良( )、中( )、一般( )、差( ); (5)论文撰写(40分):优( )、良( )、中( )、一般( )、差( );
评阅人: 职称: 讲师
2011 年 12 月 16 日
华东交通大学课程设计报告
中文摘要
学生学籍管理可以说是一项琐碎、繁杂而又必须十分细致的工作,是不能允许发生差错的。数十年前的那种手工操作已远远跟不上近代教育普及、学生数量大增的情况了,时代的进步决定了学校管理的智能化,而学校要管理到位必然要有完善的管理体系,所以说学生学籍管理的自动化完全是时代进步和教育普及所推动的必然结果。合理的利用有助于教育管理的管理系统是校园管理得当的一种优越性的体现。计算机具有运算速度快、准确、能按照设计逻辑处理问题等特性,在学生信息的录入,采用一个计算机化的信息系统进行处理,就不会发生信息遗漏或者数据输入不正确的情形。
作为计算机应用的一部分,使用计算机对学生学籍进行管理,具有手工管理所无法比拟的优点.例如查找方便、可靠性高、存储量大、保密性好、寿命长、成本低等。这些优点能够极大地提高的效率,也是学校科学化、正规化管理的重要条件。利用计算机对学生管理不仅保证了资料准确度,还成倍的提高了工作效率,而且便于管理、查询、增添等操作。
本软件界面整洁、使用方便。该系统使用java作为开发语言,该软件是一个面向对象的开发程序,其主有更大的灵活性和可扩展性。数据库通过ADO技术来与应用程序进行连接要优点是易于使用、高速度、低内存支出和占用磁盘空间较少。本系统的开发和应用,可以极大的提高学校的学生学籍管理水平,学校的办公效率也可以有很大的提高,化简了繁琐的工作模式,从而使学校的管理更加合理化和科学化。良好的信息系统节省了大量的人力和物力,也避免了大量重复性的工作。
本系统是一个复杂的信息系统,包含了信息录入、信息查询、信息修改等功能,能满足学校学生管理工作的基本要求。
华东交通大学课程设计报告
目 录
一、设计任务及要求 .......................................................................... 1 二、需求分析 ...................................................................................... 2 三、设计思路 ...................................................................................... 3 四、详细设计 ...................................................................................... 5 五、运行调试与分析讨论 ................................................................ 11 六、设计体会与小结 ........................................................................ 15 七、参考文献 .................................................................................... 16 八、附录 ............................................................................................ 17
华东交通大学课程设计报告
一、 设计任务及要求
使用JAVA语言编写一个学生学籍管理系统,使其具有以下功能:
1.录入学生基本信息的功能
2.修改学生基本信息的功能
3.查询学生基本信息的功能
4.删除学生基本信息的功能
第 1 页
华东交通大学课程设计报告
二、需求分析
信息社会的高科技,商品经济化的高效益,使计算机的应用已普及到经济和社会生活的各个领域。计算机虽然与人类的关系愈来愈密切,还有人由于计算机操作不方便继续用手工劳动。为了适应现代社会人们高度强烈的时间观念,学籍管理系统软件为教学办公室带来了极大的方便。该软件是以汉语编程语言为实现语言,其功能在系统内部有源代码直接完成。通过操作手册,使用者可以了解本软件的基本工作原理。操作人员只需输入一些简单的汉字、数字,即可达到自己的目标。
本系统的开发和应用,可以极大的提高学校的学生学籍管理水平,学校的办公效率也可以有很大的提高,化简了繁琐的工作模式,从而使学校的管理更加合理化和科学化。良好的信息系统节省了大量的人力和物力,也避免了大量重复性的工作。
第 2 页
华东交通大学课程设计报告
三、设计思路
程序主界面 输入功能 修改功能 第 3 页
查找功能 删除功能 华东交通大学课程设计报告
本学生学籍管理系统最主要的的是在于对于输入,修改,查找,删除功能的编写。
关于输入功能主要是学生学籍信息的存入,以及存储文档的建立。本系统建立了一个TXT文档来存储学生的学籍信息。需要实现的是如何把信息存入文档里。使用FileInputStream进行文件输入,使用FileOutputStream进行文件输出数据写入,使用ObjectInputStream对学生对象信息输入,使用ObjectOutputStream进行信息输出,并与存储学生信息的文档关联。
修改功能需要实现的是用现有数据覆盖文档存储的学生学籍信息。首先应该考虑是否原本文档里含有输入的学号的信息,如果有,则输入其修改信息替换掉原来的学籍信息给予保存文档。查找功能其实就是修改功能的一部分,不过当读取到对应的学生学籍信息之后,要进行对象输出,显示在界面里。删除功能中是查找功能的延续,读取到学籍信息,给予制空,对应的文档里的学生学籍信息全部为null。
所有的功能中都需要考虑到异常情况。比如,当进行输入功能时,填写人员没有填写学号而直接经行数据输入,应当给予警告。
对于界面布局方面,应当多次调试,已获得更好的显示效果。界面也应该做到简洁明了,虽然使用者不明白此系统构造,但是仍然能够很轻松的使用本系统。主界面中菜单栏的建立和录入内容用来连接学籍管理系统的功能而进行操作。
第 4 页
华东交通大学课程设计报告
四、详细设计
主界面
this.input = new JMenuItem(\"输入学生的信息\"); this.change = new JMenuItem(\"修改学生的信息\"); this.search = new JMenuItem(\"查找学生的信息\"); this.delete = new JMenuItem(\"删除学生的信息\"); Jbar = new JMenuBar(); menuj = new JMenu(\"功能\"); menuj.add(input); menuj.add(change); menuj.add(search); menuj.add(delete); Jbar.add(menuj); setJMenuBar(Jbar);
主界面主要就是建立一个窗口,在窗口中插入一个JBar菜单条,并将其设置为建立窗口的菜单条,用来储存功能。添加完菜单条后在其添加菜单menuj。接下来在菜单中添加内容,本系统只添加了input,change,search,delete四项内容用来建立功能。建立一个TXT文档用来存放string的学生各项数据,使其能实现功能。另外对其布局进行了修改,采用隶书彩色字体,使用lab1 = new JLabel(\"欢迎进入学生学籍管理系统\CENTER)使文字居中。
Student类
public class Student implements java.io.Serializable{
String name; String number; String department; String sex;
第 5 页
华东交通大学课程设计报告
String birth; String grade;
建立一个Student类用于存放学生的name,number,sex等数据,方便的被其他功能调用,被其他功能读取或者修改。
输入功能
JTextField name, number, birth, grade, department;// 学生的信息项。
JRadioButton male, female;// 单选按钮 Student Stu;
ButtonGroup group;// 形成单选效果 JButton confirm, reset; File fi1;
FileInputStream fin;// 文件输入流
FileOutputStream fou;// 文件输出流写入数据 ObjectInputStream oin;// 对象输入流 ObjectOutputStream oou;// 对象输出流 Hashtable ha1;// 哈希图数据结构来储存数据
使用FileInputStream进行文件输入,使用FileOutputStream进行文件输出数据写入,使用ObjectInputStream对学生对象信息输入,使用ObjectOutputStream进行信息输出,并与存储学生信息的文档关联。建立ha1来储存数据。考虑到学生性别信息的选择,使用单选按钮,使用JRadioButton形成单选按钮,使用ButtonGroup展示单选效果。分别建立comfire,reset按钮对所录入信息的确定和重置。当录入学生信息时,还需考虑到异常情况,当输入已经存在的学生学号时,给予警告“该生信息已存在”。当没有输入学生的学号信息就选择comfire按钮录入学生信息时,给予警告“请输入学生学号”,提醒输入。
修改功能
if (ha1.containsKey(nu)) {
confirm.setEnabled(true);
第 6 页
华东交通大学课程设计报告
}
}
Stu = (Student) ha1.get(nu); name.setText(Stu.getname()); birth.setText(Stu.getbirth());
department.setText(Stu.getdepartment()); grade.setText(Stu.getgrade()); if (Stu.getsex().equals(\"男\")) { }
String warning = \"没有该学生的信息\";
JOptionPane.showMessageDialog(this, warning, \"出number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null);
male.setSelected(true); female.setSelected(true); } else {
} else {
错了\WARNING_MESSAGE);
else {
String warning = \"必须输入学号\";
JOptionPane.showMessageDialog(this, warning, \"出错了\
视图和输入界面类似,建立盒子模型用于存放新的学生学籍信息覆盖原来的学生学籍信息。对于没有输入学生学号而进行修改信息的情况,给予“必须输入学号”的警告,如果输入的学号查找成功,文件读取数据输出,是新的信息覆盖。如果没有此学生信息也必须给出警告。
查找功能
catch (Exception e1) {
第 7 页
华东交通大学课程设计报告
}
}
}
if (ha1.containsKey(nu)) {
Stu = (Student) ha1.get(nu); name.setText(Stu.getname()); birth.setText(Stu.getbirth()); department.setText(Stu.getgrade()); grade.setText(Stu.getgrade()); if (Stu.getsex().equals(\"男\")) { }
male.setSelected(true); female.setSelected(true); } else {
}// if(ha1) else { }
String warning = \"该学生不存在!\";
JOptionPane.showMessageDialog(this, warning, \"结
果\WARNING_MESSAGE);
else { }
String warning = \"请输入学号\";
JOptionPane.showMessageDialog(this, warning, \"出错了\
JOptionPane.WARNING_MESSAGE);
else if (e.getSource() == reset) {
number.setText(null); name.setText(null); birth.setText(null); department.setText(null);
第 8 页
华东交通大学课程设计报告
}
}
}
grade.setText(null);
关于查找功能,主要就是文件数据输入和输出,读取File中的学生学籍的信息,对于异常情况的警告,则和其它情况类似。
删除功能
int ok = JOptionPane.showConfirmDialog(this, m, \"确认\
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (ok == JOptionPane.YES_OPTION) {
ha1.remove(nu); try { }
confirm.setEnabled(false);
第 9 页
fou = new FileOutputStream(fi1); oou = new ObjectOutputStream(fou); oou.writeObject(ha1); oou.close(); fou.close();
number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null);
} catch (Exception e1) {
} else if (ok == JOptionPane.NO_OPTION) {
华东交通大学课程设计报告
}
}
}
}
number.setText(null); name.setText(null); birth.setText(null); department.setText(null); birth.setText(null);
else if (e.getSource() == reset) { }
number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null);
对于删除功能使用FileInputStream fin: 文件输入流;FileOutputStream fou: 文件输出流写入数据;ObjectInputStream oin: 对象输入流;
ObjectOutputStream oou: 对象输出流。使得对应学号的File中的的学生学籍信息制空。如果查找不到对应学号或没有输入学号则输出警告。
第 10 页
华东交通大学课程设计报告
五、运行调试与分析讨论
主界面
主界面主要就是菜单及菜单选项的建立,以及文字布局方面。
第 11 页
华东交通大学课程设计报告
输入界面
输入的学生学籍信息的都将被存放在fin1里,以便修改查找功能的使用
对于学号没有输入时要给予警告,当点击重置按钮时,所有已经填写的内容都将被清除掉。
第 12 页
华东交通大学课程设计报告
修改界面
没有该学号学生信息时,给予警告,当不输入学号就进行修改功能时,也会弹出警告。
第 13 页
华东交通大学课程设计报告
查询界面
查询功能主要是对文件的读取和数据的输出
删除界面
删除功能是删除Fil1里的所对应学号的学生信息
第 14 页
华东交通大学课程设计报告
六、设计体会与小结
通过这次课程设计我觉得收获了很多。在本次课设中,我遇到了好多自己不能解决的问题,同学和网络的帮助无疑对自己帮助很大。像窗口中菜单的建立和使用,学习了别人的代码之后才明白如何使用操作。对于那些书本里没有的知识,我们也需要掌握,这有利于我们拓展自己的知识面,是自己在以后的学习中更加轻松自如。
要注意细节。可能只是中文字符的错误,也使是自己的程序出现错误。在以后的学习过程中,要更加的仔细认真。在当时看来仔仔细细的斟酌肯能会使自己的速度降低,但是这样可以大量减少自己的错误,其实节省了大量的时间用来修改。
对自己要有信心。虽然在课设中,自己的错误很多,有的东西也完全不理解,但是我仍然对自己有信心。有信心自己能完成课设,我可以求助于网络,请教同学。自信心十分重要。
第 15 页
华东交通大学课程设计报告
七、参考文献
[1] 丁振凡,薛清华. Java语言程序设计[M]. 出版地:北京 出版社名称:清华大学出版社 出版年限:2010.10
[2] 丁振凡,李宪伟.Java语言与习题解答[M]. 出版地:北京 出版社名称:清华大学出版社 出版年限:2010.10
第 16 页
华东交通大学课程设计报告
八、附录
主界面
package student; import java.awt.*;
import java.awt.event.*; import javax.swing.*; import java.io.*;
import java.util.Hashtable;
public class Stuaccess extends JFrame implements ActionListener { Container con; JMenuBar Jbar; JMenu menuj;
JMenuItem input, change, search, delete;// 四项功能输入,修改,查找,删除 JLabel lab1; JPanel JCenter; File fi1;
Hashtable ha1; input intinfo; change chginfo; search schinfo; delete delinfo;
public Stuaccess() {
super(\"华东交通大学学籍管理系统\"); con = getContentPane();
con.setLayout(new BorderLayout()); ha1 = new Hashtable();
fi1 = new File(\"学生的学籍信息.txt\"); if (!fi1.exists()) { try { FileOutputStream out = new FileOutputStream(fi1); ObjectOutputStream objectOut = new ObjectOutputStream(out);
objectOut.writeObject(ha1);
第 17 页
华东交通大学课程设计报告
objectOut.close(); out.close(); }// try catch (IOException e) { } }// if
this.input = new JMenuItem(\"输入学生的信息\"); this.change = new JMenuItem(\"修改学生的信息\"); this.search = new JMenuItem(\"查找学生的信息\"); this.delete = new JMenuItem(\"删除学生的信息\"); Jbar = new JMenuBar();
menuj = new JMenu(\"功能\"); menuj.add(input); menuj.add(change); menuj.add(search); menuj.add(delete); Jbar.add(menuj); setJMenuBar(Jbar);
lab1 = new JLabel(\"欢迎进入学生学籍管理系统\CENTER); lab1.setFont(new Font(\"隶书\BOLD, 30)); lab1.setForeground(Color.green); add(lab1,BorderLayout.CENTER); setBounds(100,100,500,400); input.addActionListener(this); change.addActionListener(this); search.addActionListener(this); delete.addActionListener(this); intinfo = new inputStuinfo(fi1); chginfo = new changeStuinfo(fi1); delinfo = new deleteStuinfo(fi1); schinfo = new searchStuinfo(fi1); //con.setVisible(true); con.validate(); setVisible(true); setSize(500, 400); con.validate();
第 18 页
华东交通大学课程设计报告
}
}
public void actionPerformed(ActionEvent e) { if (e.getSource() == input) { intinfo.setVisible(true); chginfo.setVisible(false); delinfo.setVisible(false); schinfo.setVisible(false);
} else if (e.getSource() == serch) { intinfo.setVisible(false); chginfo.setVisible(false); delinfo.setVisible(false); schinfo.setVisible(true); }else if(e.getSource()==change){ intinfo.setVisible(false); chginfo.setVisible(true); delinfo.setVisible(false); schinfo.setVisible(false); }
else if(e.getSource()==delete){ intinfo.setVisible(false); chginfo.setVisible(false); delinfo.setVisible(true); schinfo.setVisible(false); } }
public static void main(String args[]) { new Stuaccess(); }
Student类
package student;
public class Student implements java.io.Serializable{ String name; String number; String department;
第 19 页
华东交通大学课程设计报告
String sex; String birth; String grade;
public Student(){}
public void setname(String name){ this.name=name; }
public String getname(){ return this.name; }
public void setnumber(String number){ this.number=number; }
public String getnumber(){ return this.number; }
public void setdepartment(String department){ this.department=department; }
public String getdepartment(){ return this.department; }
public void setsex(String sex){ this.sex=sex; }
public String getsex(){ return this.sex; }
public void setbirth(String birth){ this.birth=birth; }
public String getbirth(){ return this.birth; }
public void setgrade(String grade){ this.grade=grade; }
第 20 页
华东交通大学课程设计报告
public String getgrade(){ return this.grade; } }
输入功能
package student; import java.awt.*;
import java.awt.event.*; import javax.swing.*; import java.io.*;
import java.util.Hashtable;
public class input extends JFrame implements ActionListener { JTextField name, number, birth, grade, department;// 学生的信息项。\\ JRadioButton male, female;// 单选按钮 Student Stu; ButtonGroup group;// 形成单选效果 JButton confirm, reset; File fi1; FileInputStream fin;// 文件输入流 FileOutputStream fou;// 文件输出流写入数据 ObjectInputStream oin;// 对象输入流 ObjectOutputStream oou;// 对象输出流 Hashtable ha1;// 哈希图数据结构来储存数据 public input(File file) { super(\"输入界面\"); this.fi1 = file; name = new JTextField(10); number = new JTextField(10); birth = new JTextField(10); grade = new JTextField(10); department = new JTextField(10); group = new ButtonGroup(); male = new JRadioButton(\"男\ female = new JRadioButton(\"女\ group.add(male); group.add(female);
第 21 页
华东交通大学课程设计报告
confirm = new JButton(\"录入\"); reset = new JButton(\"重置\"); ha1 = new Hashtable();
confirm.addActionListener(this); reset.addActionListener(this);
Box box1 = Box.createHorizontalBox();
box1.add(new JLabel(\"学号:\CENTER)); box1.add(number);
Box box2 = Box.createHorizontalBox();
box2.add(new JLabel(\"姓名:\CENTER)); box2.add(name);
Box box3 = Box.createHorizontalBox();
box3.add(new JLabel(\"性别:\CENTER)); box3.add(male); box3.add(female);
Box box4 = Box.createHorizontalBox();
box4.add(new JLabel(\"专业:\CENTER)); box4.add(department);
Box box5 = Box.createHorizontalBox();
box5.add(new JLabel(\"年级:\CENTER)); box5.add(grade);
Box box6 = Box.createHorizontalBox();
box6.add(new JLabel(\"出生:\CENTER)); box6.add(birth);
Box boxc = Box.createVerticalBox();// 垂直的Box容器 boxc.add(box1); boxc.add(box2); boxc.add(box3); boxc.add(box4); boxc.add(box5); boxc.add(box6);
boxc.add(Box.createVerticalGlue());// 尽可能把上面的box分开。 JPanel JP1 = new JPanel(); JP1.add(boxc);
JPanel JP2 = new JPanel(); JP2.add(confirm); JP2.add(reset);
第 22 页
华东交通大学课程设计报告
}
setLayout(new BorderLayout()); add(JP1, BorderLayout.CENTER); add(JP2, BorderLayout.SOUTH); validate();// 确保布局的有效性。 setBounds(300, 500, 200, 300); setSize(500, 300); // setVisible(false);
public void actionPerformed(ActionEvent e) { if (e.getSource() == confirm) { String nu = \"\"; nu = number.getText(); if (nu.length() > 0) { try { fin = new FileInputStream(fi1); oin = new ObjectInputStream(fin); ha1 = (Hashtable) oin.readObject(); fin.close(); oin.close(); }// try catch (Exception e1) { } if (ha1.containsKey(nu)) { String warning = \"该生信息已存在\";
JOptionPane.showMessageDialog(this, warning, \"重复了\ JOptionPane.WARNING_MESSAGE); } else { String m = \"基本信息将被录入!\"; int ok = JOptionPane.showConfirmDialog(this, m, \"确认\ JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { String na = name.getText(); String bir = birth.getText(); String dep = department.getText();
第 23 页
华东交通大学课程设计报告
String gra = grade.getText(); String se;
if (male.isSelected()) { se = male.getText(); } else { se = female.getText(); }
Stu = new Student(); Stu.setnumber(nu); Stu.setname(na); Stu.setbirth(bir);
Stu.setdepartment(dep); Stu.setgrade(gra); Stu.setsex(se); try { fou = new FileOutputStream(fi1); oou = new ObjectOutputStream(fou); ha1.put(nu, Stu); oou.writeObject(ha1); oou.close(); fou.close(); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null);
} catch (Exception ee) {
System.out.println(ee); } } } }// if else { String warning = \"请确认已经输入学号\"; JOptionPane.showMessageDialog(this, warning, \"出错了\ JOptionPane.WARNING_MESSAGE);
第 24 页
华东交通大学课程设计报告
}
}
} }// if
if (e.getSource() == reset) { number.setText(null); name.setText(null); birth.setText(null);
department.setText(null); grade.setText(null); }
修改功能
package student; import java.awt.*;
import java.awt.event.*; import javax.swing.*; import student.Student; import java.io.*; import java.util.*;
public class change extends JFrame implements ActionListener { Student Stu, Stu1; Container con;
JTextField name, number, birth, grade, department;// 学生的信息项。 JRadioButton male, female;// 单选按钮 ButtonGroup group;// 形成单选效果 JButton find, confirm, reset; File fi1;
FileInputStream fin;// 文件输入流
FileOutputStream fou;// 文件输出流写入数据 ObjectInputStream oin;// 对象输入流 ObjectOutputStream oou;// 对象输出流
Hashtable ha1;// 哈希表数据结构来储存数据 public change(File file) { super(\" 修改界面\"); this.fi1 = file;
con = con = getContentPane();
第 25 页
华东交通大学课程设计报告
Hashtable ha1 = new Hashtable(); name = new JTextField(10); number = new JTextField(10); birth = new JTextField(10); grade = new JTextField(10);
department = new JTextField(10); group = new ButtonGroup();
male = new JRadioButton(\"男\ female = new JRadioButton(\"女\ group.add(male); group.add(female);
find = new JButton(\"开始修改\"); confirm = new JButton(\"录入修改\"); confirm.setEnabled(false); reset = new JButton(\"重置\"); number.addActionListener(this); find.addActionListener(this); confirm.addActionListener(this); reset.addActionListener(this);
Box box1 = Box.createHorizontalBox();//盒子模型
box1.add(new JLabel(\"请输入要修改信息的学号:JLabel.CENTER));
box1.add(number); box1.add(find);
Box box2 = Box.createHorizontalBox();
box2.add(new JLabel(\"(新)姓名:\CENTER)); box2.add(name);
Box box3 = Box.createHorizontalBox();
box3.add(new JLabel(\"(新)性别:\CENTER)); box3.add(male); box3.add(female);
Box box4 = Box.createHorizontalBox();
box4.add(new JLabel(\"(新)专业:\CENTER)); box4.add(department);
Box box5 = Box.createHorizontalBox();
box5.add(new JLabel(\"(新)年级:\CENTER)); box5.add(grade);
第 26 页
\华东交通大学课程设计报告
}
Box box6 = Box.createHorizontalBox();
box6.add(new JLabel(\"(新)出生:\CENTER)); box6.add(birth);
Box boxc = Box.createVerticalBox();// 垂直的Box容器 boxc.add(box1); boxc.add(box2); boxc.add(box3); boxc.add(box4); boxc.add(box5); boxc.add(box6);
boxc.add(Box.createVerticalGlue());// 尽可能把上面的box分开。 setLayout(new BorderLayout()); JPanel JP1 = new JPanel(); JP1.add(boxc);
JPanel JP2 = new JPanel(); JP2.add(confirm); JP2.add(reset);
con.add(JP1, BorderLayout.CENTER); con.add(JP2, BorderLayout.SOUTH); setBounds(300, 500, 200, 300); setSize(500, 300);
validate();// 确保布局的有效性。
public void actionPerformed(ActionEvent e) {
if (e.getSource() == find || e.getSource() == number) { String nu = \"\"; nu = number.getText(); if (nu.length() > 0) { try { fin = new FileInputStream(fi1); oin = new ObjectInputStream(fin); ha1 = (Hashtable) oin.readObject(); fin.close(); oin.close(); }// try catch (Exception e1) {
第 27 页
华东交通大学课程设计报告
} if (ha1.containsKey(nu)) { confirm.setEnabled(true); Stu = (Student) ha1.get(nu); name.setText(Stu.getname()); birth.setText(Stu.getbirth()); department.setText(Stu.getdepartment()); grade.setText(Stu.getgrade()); if (Stu.getsex().equals(\"男\")) { male.setSelected(true); } else { female.setSelected(true); } } else { String warning = \"没有该学生的信息\"; JOptionPane.showMessageDialog(this, warning, \"出错了\ JOptionPane.WARNING_MESSAGE); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); } } else { // find.setEnabled(false);
String warning = \"必须输入学号\"; JOptionPane.showMessageDialog(this, warning, \"出错了\ JOptionPane.WARNING_MESSAGE); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); }
} else if (e.getSource() == confirm) {
第 28 页
华东交通大学课程设计报告
String nu = \"\";
nu = number.getText(); if (nu.length() > 0) { try { fin = new FileInputStream(fi1); oin = new ObjectInputStream(fin); ha1 = (Hashtable) oin.readObject(); fin.close(); oin.close(); } catch (Exception e1) { } if (ha1.containsKey(nu)) { String q = \"确认修改该学生的信息?\";
JOptionPane.showMessageDialog(this, q, \"出错了\ JOptionPane.QUESTION_MESSAGE); String m = \"该学生的学籍信息将被修改。\";
int ok = JOptionPane.showConfirmDialog(this, m, \"确认\ JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { String na = name.getText(); String bir = birth.getText(); String dep = department.getText(); String gra = grade.getText(); String se; if (male.isSelected()) { se = male.getText(); } else { se = female.getText(); } Stu1 = new Student(); Stu1.setnumber(nu); Stu1.setname(na); Stu1.setbirth(bir);
第 29 页
华东交通大学课程设计报告
}
Stu1.setdepartment(dep); Stu1.setgrade(gra); Stu1.setsex(se); try { fou = new FileOutputStream(fi1); oou = new ObjectOutputStream(fou); ha1.put(nu, Stu1); oou.writeObject(ha1); oou.close(); fou.close(); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); } catch (Exception e1) { } confirm.setEnabled(false); } else if (ok == JOptionPane.NO_OPTION) { confirm.setEnabled(true); } } else { String warning = \"没有该学生的信息\"; JOptionPane.showMessageDialog(this, warning, \"出错了\ JOptionPane.WARNING_MESSAGE); confirm.setEnabled(false); } } else { String warning = \"请输入学号\"; JOptionPane.showMessageDialog(this, warning, \"出错了\ JOptionPane.WARNING_MESSAGE); confirm.setEnabled(false); }
第 30 页
华东交通大学课程设计报告
}
}
if (e.getSource() == reset) { confirm.setEnabled(false); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); }
查找功能
package student; import java.awt.*;
import java.awt.event.*; import javax.swing.*; import student.Student; import java.io.*; import java.util.*;
public class search extends JFrame implements ActionListener { Student Stu, Stu1; Container con;
JTextField name, number, birth, grade, department;// 学生的信息项。 JRadioButton male, female;// 单选按钮 ButtonGroup group;// 形成单选效果 JButton find, confirm, reset; File fi1;
FileInputStream fin;// 文件输入流
FileOutputStream fou;// 文件输出流写入数据 ObjectInputStream oin;// 对象输入流 ObjectOutputStream oou;// 对象输出流
Hashtable ha1 = null;// 哈希表数据结构来储存数据 public search(File file) { super(\"查询界面\"); this.fi1 = file;
con = con = getContentPane(); name = new JTextField(10);
第 31 页
华东交通大学课程设计报告
name.setEnabled(false);
number = new JTextField(10); number.setEnabled(true); birth = new JTextField(10); birth.setEnabled(false);
grade = new JTextField(10); grade.setEnabled(false);
department = new JTextField(10); department.setEnabled(false); group = new ButtonGroup();
male = new JRadioButton(\"男\female = new JRadioButton(\"女\group.add(male); group.add(female);
find = new JButton(\"查找\"); reset = new JButton(\"重置\"); ha1 = new Hashtable();
number.addActionListener(this); find.addActionListener(this); reset.addActionListener(this);
Box box1 = Box.createHorizontalBox();
box1.add(new JLabel(\"请输入学号:\CENTER)); box1.add(number); box1.add(find);
Box box2 = Box.createHorizontalBox();
box2.add(new JLabel(\"姓名:\CENTER)); box2.add(name);
Box box3 = Box.createHorizontalBox();
box3.add(new JLabel(\"性别:\CENTER)); box3.add(male); box3.add(female);
Box box4 = Box.createHorizontalBox();
box4.add(new JLabel(\"专业:\CENTER)); box4.add(department);
Box box5 = Box.createHorizontalBox();
box5.add(new JLabel(\"年级:\CENTER)); box5.add(grade);
第 32 页
华东交通大学课程设计报告
}
Box box6 = Box.createHorizontalBox();
box6.add(new JLabel(\"出生:\CENTER)); box6.add(birth);
Box boxc = Box.createVerticalBox();// 垂直的Box容器 boxc.add(box1); boxc.add(box2); boxc.add(box3); boxc.add(box4); boxc.add(box5); boxc.add(box6);
boxc.add(Box.createVerticalGlue());// 尽可能把上面的box分开。 setLayout(new BorderLayout()); JPanel JP1 = new JPanel(); JP1.add(boxc);
JPanel JP2 = new JPanel(); JP2.add(reset);
con.add(JP1, BorderLayout.CENTER); con.add(JP2, BorderLayout.SOUTH); setBounds(300, 500, 200, 300); setSize(500,300);
validate();// 确保布局的有效性。
addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); } };
public void actionPerformed(ActionEvent e) { name.setText(null); birth.setText(null);
department.setText(null); grade.setText(null);
if (e.getSource() == find || e.getSource() == number) { String nu = \"\"; nu = number.getText(); if (nu.length() > 0) {
第 33 页
华东交通大学课程设计报告
try { fin = new FileInputStream(fi1); oin = new ObjectInputStream(fin); ha1 = (Hashtable) oin.readObject(); fin.close(); oin.close(); }// try catch (Exception e1) { } if (ha1.containsKey(nu)) { Stu = (Student) ha1.get(nu); name.setText(Stu.getname()); birth.setText(Stu.getbirth()); department.setText(Stu.getgrade()); grade.setText(Stu.getgrade()); if (Stu.getsex().equals(\"男\")) { male.setSelected(true); } else { female.setSelected(true); }
}// if(ha1) else { String warning = \"该学生不存在!\"; JOptionPane.showMessageDialog(this, warning, \"结果\WARNING_MESSAGE); } } else { String warning = \"请输入学号\"; JOptionPane.showMessageDialog(this, warning, \"出错了\ JOptionPane.WARNING_MESSAGE); } }
else if (e.getSource() == reset) { number.setText(null); name.setText(null);
第 34 页
华东交通大学课程设计报告
}
}
}
birth.setText(null);
department.setText(null); grade.setText(null);
删除功能
package student; import java.awt.*;
import java.awt.event.*; import javax.swing.*; import student.Student; import java.io.*; import java.util.*;
public class delete extends JFrame implements ActionListener { Student Stu, Stu1; Container con;
JTextField name, number, birth, grade, department;// 学生的信息项。 JRadioButton male, female;// 单选按钮 ButtonGroup group;// 形成单选效果 JButton find, confirm, reset; File fi1;
FileInputStream fin;// 文件输入流
FileOutputStream fou;// 文件输出流写入数据 ObjectInputStream oin;// 对象输入流 ObjectOutputStream oou;// 对象输出流
Hashtable ha1;// 哈希表数据结构来储存数据 String nu = \"\";
public delete(File file) { super(\"删除界面\"); this.fi1 = file;
ha1 = new Hashtable();
con = con = getContentPane(); name = new JTextField(10); number = new JTextField(10); birth = new JTextField(10);
第 35 页
华东交通大学课程设计报告
grade = new JTextField(10);
department = new JTextField(10); group = new ButtonGroup();
male = new JRadioButton(\"男\female = new JRadioButton(\"女\group.add(male); group.add(female);
find = new JButton(\"查找\"); confirm = new JButton(\"删除\"); confirm.setEnabled(false); reset = new JButton(\"重置\"); number.addActionListener(this); find.addActionListener(this); confirm.addActionListener(this); reset.addActionListener(this);
Box box1 = Box.createHorizontalBox();
box1.add(new JLabel(\"输入要删除的学号:\CENTER)); box1.add(number); box1.add(find);
Box box2 = Box.createHorizontalBox();
box2.add(new JLabel(\"姓名:\CENTER)); box2.add(name);
Box box3 = Box.createHorizontalBox();
box3.add(new JLabel(\"性别:\CENTER)); box3.add(male); box3.add(female);
Box box4 = Box.createHorizontalBox();
box4.add(new JLabel(\"专业:\CENTER)); box4.add(department);
Box box5 = Box.createHorizontalBox();
box5.add(new JLabel(\"年级:\CENTER)); box5.add(grade);
Box box6 = Box.createHorizontalBox();
box6.add(new JLabel(\"出生:\CENTER)); box6.add(birth);
Box boxc = Box.createVerticalBox();// 垂直的Box容器 boxc.add(box1);
第 36 页
华东交通大学课程设计报告
}
boxc.add(box2); boxc.add(box3); boxc.add(box4); boxc.add(box5); boxc.add(box6);
boxc.add(Box.createVerticalGlue());// 尽可能把上面的box分开。 setLayout(new BorderLayout()); JPanel JP1 = new JPanel(); JP1.add(boxc);
JPanel JP2 = new JPanel(); JP2.add(confirm); JP2.add(reset);
con.add(JP1, BorderLayout.CENTER); con.add(JP2, BorderLayout.SOUTH); setBounds(300, 500, 200, 300); setSize(500, 300);
validate();// 确保布局的有效性。
public void actionPerformed(ActionEvent e) {
if (e.getSource() == find || e.getSource() == number) {
nu = number.getText(); if (nu.length() > 0) { try { fin = new FileInputStream(fi1); oin = new ObjectInputStream(fin); ha1 = (Hashtable) oin.readObject(); fin.close(); oin.close(); }// try catch (Exception e1) { } if (ha1.containsKey(nu)) { confirm.setEnabled(true); Stu = (Student) ha1.get(nu);
第 37 页
华东交通大学课程设计报告
confirm.setEnabled(true); Stu = (Student) ha1.get(nu); name.setText(Stu.getname()); birth.setText(Stu.getbirth());
department.setText(Stu.getdepartment()); grade.setText(Stu.getgrade());
}
else if (e.getSource() == confirm) { String m = \"确定要删除该学生的信息吗?\";
第 38 页
} else { find.setEnabled(false); String warning = \"请输入学号\";
JOptionPane.showMessageDialog(this, warning, \"出错了\WARNING_MESSAGE); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); }
if (Stu.getsex().equals(\"男\")) { male.setSelected(true); } else { female.setSelected(true); } } else { String warning = \"没有该学生的信息\";
JOptionPane.showMessageDialog(this, warning, \"出错了\ JOptionPane.WARNING_MESSAGE); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); }
华东交通大学课程设计报告
}
int ok = JOptionPane.showConfirmDialog(this, m, \"确认\
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { ha1.remove(nu); try { fou = new FileOutputStream(fi1); oou = new ObjectOutputStream(fou); oou.writeObject(ha1); oou.close(); fou.close(); number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); } catch (Exception e1) { } confirm.setEnabled(false);
} else if (ok == JOptionPane.NO_OPTION) { number.setText(null); name.setText(null); birth.setText(null); department.setText(null); birth.setText(null); }
}
else if (e.getSource() == reset) { number.setText(null); name.setText(null); birth.setText(null); department.setText(null); grade.setText(null); }
第 39 页
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务