StudentManager论文文档格式.docx
《StudentManager论文文档格式.docx》由会员分享,可在线阅读,更多相关《StudentManager论文文档格式.docx(22页珍藏版)》请在冰豆网上搜索。
变量名称
显示注释的标签
JLabel
lb
显示欢迎进入的标签
欢迎
设定字体属性
Font
font1
输入学生基本信息的文本
JTextField
学号,姓名,专业,年级,出生,电话,住址
性别选择
JRadioButton
男,女
进行相应操作的按钮
JButton
录入,查询,删除,修改,显示,进入,确定,退出
调整布局的通道
JPanel
p01,p02,p03,p04,p1,p2,p3,p4,p5,p6,p7,p8,p9,pv,ph,plb
系统框架界面
JFrame
Welcome,operation
存放学生基本信息的对象
Student
学生
学生信息的散列表
Hashtable
基本信息
存放散列表的文件
File
file
2).方法
主要方法
名称
功能
备注
StudentManager
创建程序主窗口
构造方法
Main
程序开始运行
3).内部类
InputAct
学生信息录入界面
InquestAct
学生信息查询界面
ModifyAct
学生信息修改界面
DeleteAct
学生信息删除界面
ShowAct
学生信息显示界面
4).代码
StudentManager.java
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjava.io.*;
importjava.util.*;
publicclassStudentManagerextendsJFrame{
JLabellb=newJLabel("
注:
录入请先输入记录,查询、删除请先输入学号,修改是对查询"
+"
内容改后的保存!
"
);
JLabel欢迎;
Fontfont1=newFont("
黑体"
Font.BOLD,24);
JTextField学号,姓名,专业,年级,出生,电话,住址;
JRadioButton男,女;
ButtonGroupgroup=null;
JButton录入,查询,删除,修改,显示,进入,确定,退出;
JPanelp01,p02,p03,p04,p1,p2,p3,p4,p5,p6,p7,p8,p9,pv,ph,plb;
Student学生=null;
Hashtable学生散列表=null;
Filefile=null;
FileInputStreaminOne=null;
ObjectInputStreaminTwo=null;
FileOutputStreamoutOne=null;
ObjectOutputStreamoutTwo=null;
publicStudentManager(){
finalJFramewelcome=newJFrame();
finalJFrameoperation=newJFrame();
p01=newJPanel();
……
欢迎=newJLabel("
欢迎进入班级管理系统!
欢迎.setFont(font1);
进入=newJButton("
进入"
退出=newJButton("
退出"
welcome.setLayout(newGridLayout(3,1,5,5));
p01.add(欢迎);
p02.add(进入);
welcome.add(p03);
welcome.add(p01);
welcome.add(p02);
welcome.setTitle("
班级管理系统"
welcome.setSize(500,300);
welcome.setVisible(true);
进入.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
welcome.setVisible(false);
operation.setVisible(true);
}
});
退出.addActionListener(newActionListener(){
System.exit(0);
operation.setTitle("
学号=newJTextField(10);
……
group=newButtonGroup();
男=newJRadioButton("
男"
true);
女=newJRadioButton("
女"
false);
group.add(男);
group.add(女);
录入=newJButton("
录入"
录入.addActionListener(newInputAct());
修改.setEnabled(false);
确定.setVisible(false);
确定.addActionListener(newActionListener(){
姓名.setEnabled(true);
男.setEnabled(true);
女.setEnabled(true);
}
p1=newJPanel();
p1.add(newJLabel("
学号:
JLabel.CENTER));
p1.add(学号);
p9=newJPanel();
p9.add(确定);
pv=newJPanel();
pv.setLayout(newGridLayout(10,1));
pv.add(p04);
pv.add(p1);
pv.add(p9);
ph=newJPanel();
ph.add(录入);
ph.add(退出);
plb=newJPanel();
plb.add(lb);
file=newFile("
学生信息.txt"
学生散列表=newHashtable();
if(!
file.exists()){
try{
FileOutputStreamout=newFileOutputStream(file);
ObjectOutputStreamobjectOut=newObjectOutputStream(out);
objectOut.writeObject(学生散列表);
objectOut.close();
out.close();
}
catch(IOExceptione){}
operation.setLayout(newBorderLayout());
operation.add(ph,BorderLayout.NORTH);
operation.add(pv,BorderLayout.CENTER);
operation.add(plb,BorderLayout.SOUTH);
operation.setDefaultCloseOperation(EXIT_ON_CLOSE);
operation.setSize(700,500);
operation.setVisible(false);
}
(1).录入界面InputAct类
1).成员变量
主要成员变量
描述
获取输入的学号,姓名,专业,年级,出生,住址,电话
String
number,name,specialty,grade,borth,address,phonenumber,sex
actionPerformed
处理ActionEvent事件
接口方法
3).代码
classInputActimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
Stringnumber="
;
number=学号.getText();
if(number.length()>
0){
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
学生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
catch(Exceptionee){System.out.println("
创建散列表出现问题!
if(学生散列表.containsKey(number)){
Stringwarning="
该生信息已存在,请到修改页面修改!
JOptionPane.showMessageDialog(null,warning,"
警告"
JOptionPane.WARNING_MESSAGE);
else{
Stringm="
该生信息将被录入!
intok=JOptionPane.showConfirmDialog(null,m,"
确认"
JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
if(ok==JOptionPane.YES_OPTION){
Stringname=姓名.getText();
Stringspecialty=专业.getText();
Stringgrade=年级.getText();
Stringborth=出生.getText();
Stringaddress=住址.getText();
Stringphonenumber=电话.getText();
Stringsex=null;
if(男.isSelected()){sex=男.getText();
else{sex=女.getText();
学生=newStudent();
学生.setNumber(number);
学生.setName(name);
学生.setSpecialty(specialty);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
outOne=newFileOutputStream(file);
outTwo=newObjectOutputStream(outOne);
学生散列表.put(number,学生);
outTwo.writeObject(学生散列表);
outTwo.close();
outOne.close();
输出散列表出现问题!
学号.setText(null);
姓名.setText(null);
专业.setText(null);
年级.setText(null);
出生.setText(null);
必须输入学号!
JOptionPane.showMessageDialog(null,warning,
"
JOptionPane.WARNING_MESSAGE);
(2).查询界面InquestAct类
变量属性
获取输入的学号
number
主要方法
3).代码
classInquestActimplementsActionListener{
散列表有问题!
修改.setEnabled(true);
Studentstu=(Student)学生散列表.get(number);
姓名.setText(stu.getName());
专业.setText(stu.getSpecialty());
年级.setText(stu.getGrade());
出生.setText(stu.getBorth());
if(stu.getSex().equals("
)){男.setSelected(true);
else{女.setSelected(true);
该学号不存在!
姓名.setEnabled(false);
男.setEnabled(false);
女.setEnabled(false);
专业.setEnabled(false);
年级.setEnabled(false);
出生.setEnabled(false);
电话.setEnabled(false);
住址.setEnabled(false);
确定.setVisible(true);
录入.setEnabled(false);
删除.setEnabled(false);
显示.setEnabled(false);
(3).修改界面ModifyAct类
获取修改的学号,姓名,专业,年级,出生,住址,电话
2).方法
classModifyActimplementsActionListener{
Stringnumber=学号.getText();
确定要保存修改该学生的记录吗?
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(ok==JOptionPane.YES_OPTION)
{
Student学生=newStudent();
学生.setNumber(number);
学生.setName(name);
学生.setSpecialty(specialty);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
学生.setAddress(address);
学生.setPhonenumber(phonenumber);
try{
outOne=newFileOutputStream(file);
outTwo=newObjectOutputStream(outOne);
学生散列表.put(number,学生);
outTwo.writeObject(学生散列表);
outTwo.close();
outOne.close();
学号.setText(null);
姓名.setText(null);
专业.setText(null);
年级.setText(null);
出生.setText(null);
电话.setText(null);
住址.setText(null);
}
catch(Exceptionee){
System.out.println("
录入修改出现异常!
修改.setEnabled(false);
(4).删除界面DeleteAct类
classDeleteActimplementsActionListener{
catch(Exceptionee){}
电话.setText(stu.getPhonenumber());
住址.setText(stu.getAddress());
确定要删除该学生的记录吗?
学生散列表.remove(number);
outTwo.w