JAVA学生管理系统.docx
《JAVA学生管理系统.docx》由会员分享,可在线阅读,更多相关《JAVA学生管理系统.docx(35页珍藏版)》请在冰豆网上搜索。
![JAVA学生管理系统.docx](https://file1.bdocx.com/fileroot1/2023-2/13/c953f839-8ee5-4814-9715-dacba3fe4598/c953f839-8ee5-4814-9715-dacba3fe45981.gif)
JAVA学生管理系统
XXXXXXX
课程设计报告
课程名称:
JAVA程序设计
项目名称:
学生信息管理系统
班级:
20XXX级软件技术JAVA方向
指导教师:
XXXX
学号:
XXX
姓名:
XXX
时间:
XXXX
一、课程设计题目
二、课程设计需求分析
三、课程设计各类之间的关系
四、Java源文件及其功能
五、主要模块代码实现
(1)主界面:
(2)importjava.io.*;
importjava.util.Hashtable;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
classupdataextendsPanelimplementsActionListener
{
Boxbox41,box42,box43,box44,box45,box46,box47;
ColorbackColor;
TextFieldnumber41,number42,number43,number44,number45;
Buttonbutton43;
Checkboxnan,nv;
CheckboxGroupsex41;
Filefile=null;
staticHashtableShashtable=null;
staticFileInputStreaminOne=null;
staticObjectInputStreaminTwo=null;
staticFileOutputStreamoutOne=null;
staticObjectOutputStreamoutTwo=null;
updata()
{
box41=Box.createHorizontalBox();
box41.add(newLabel("输入需要修改的学号:
"));
number41=newTextField(10);
button43=newButton("开始修改");
button43.addActionListener(this);
box41.add(number41);
box41.add(Box.createHorizontalStrut(5));
box41.add(button43);
file=newFile("G:
\\","学生管理系统.txt");
box42=Box.createHorizontalBox();
box42.add(newLabel("(新)姓名:
"));
number42=newTextField(20);
box42.add(number42);
sex41=newCheckboxGroup();
nan=newCheckbox("男",true,sex41);
nv=newCheckbox("女",false,sex41);
box43=Box.createHorizontalBox();
box43.add(newLabel("(新)性别:
"));
box43.add(nan);
box43.add(nv);
box44=Box.createHorizontalBox();
box44.add(newLabel("(新)专业:
"));
number43=newTextField(20);
box44.add(number43);
box45=Box.createHorizontalBox();
box45.add(newLabel("(新)班级:
"));
number44=newTextField(20);
box45.add(number44);
box46=Box.createHorizontalBox();
box46.add(newLabel("(新)出生:
"));
number45=newTextField(20);
box46.add(number45);
box47=Box.createVerticalBox();
box47.add(Box.createVerticalStrut(20));
box47.add(box41);
box47.add(Box.createVerticalStrut(8));
box47.add(box42);
box47.add(Box.createVerticalStrut(8));
box47.add(box43);
box47.add(Box.createVerticalStrut(8));
box47.add(box44);
box47.add(Box.createVerticalStrut(8));
box47.add(box45);
box47.add(Box.createVerticalStrut(8));
box47.add(box46);
box47.add(Box.createVerticalStrut(8));
setBackground(Color.lightGray);
add(box47);
setVisible(true);
}
publicvoidactionPerformed(ActionEvente)
{
try{
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
Shashtable=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exceptionee)
{
System.out.println("散列表有问题!
");
}
Stringnumber=number41.getText();
Stringname=number42.getText();
Stringbanji=number43.getText();
Stringzhuanye=number44.getText();
Stringdata=number45.getText();
Stringsex=null;
if(nan.getState())
{sex=nan.getLabel();}
else
{sex=nv.getLabel();}
Student学生=newStudent();
学生.setNumber(number);
学生.setName(name);
学生.setbanji(banji);
学生.setzhuanye(zhuanye);
学生.setdata(data);
学生.setSex(sex);
try{
outOne=newFileOutputStream(file);
outTwo=newObjectOutputStream(outOne);
Shashtable.put(学生.number,学生);
outTwo.writeObject(Shashtable);
outTwo.close();
outOne.close();
number41.setText(null);
number42.setText(null);
number43.setText(null);
number44.setText(null);
number45.setText(null);
}
catch(Exceptionee){
System.out.println("录入修改出现异常!
");
}
}
}
(2)学生基本信息的录入功能
importjava.io.*;
importjava.util.Hashtable;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
classluruextendsPanelimplementsActionListener
{
Boxbox21,box22,box23,box24,box25,box29,box28,box210;
TextFieldnumber,name,banji,zhuanye,data;
Buttonbutton21,button22;
Checkboxbox26,box27;
CheckboxGroupsex;
Filefile=null;
staticStudentstudent=null;
staticHashtableShashtable=null;
staticFileInputStreaminOne=null;
staticObjectInputStreaminTwo=null;
staticFileOutputStreamoutOne=null;
staticObjectOutputStreamoutTwo=null;
luru()
{
number=newTextField(12);
name=newTextField(12);
banji=newTextField(12);
zhuanye=newTextField(12);
data=newTextField(12);
file=newFile("G:
\\","学生管理系统.txt");
Shashtable=newHashtable();
if(!
file.exists()){
try{
FileOutputStreamout=newFileOutputStream(file);
ObjectOutputStreamobjectOut=newObjectOutputStream(out);
objectOut.writeObject(Shashtable);
objectOut.close();
out.close();
}
catch(IOExceptione){}
}
box21=Box.createHorizontalBox();
box21.add(newLabel("学号:
"));
box21.add(number);
box22=Box.createHorizontalBox();
box22.add(newLabel("姓名:
"));
box22.add(name);
box23=Box.createHorizontalBox();
box23.add(newLabel("专业:
"));
box23.add(zhuanye);
box24=Box.createHorizontalBox();
box24.add(newLabel("班级:
"));
box24.add(banji);
box25=Box.createHorizontalBox();
box25.add(newLabel("出生:
"));
box25.add(data);
sex=newCheckboxGroup();
box26=newCheckbox("男",true,sex);
box27=newCheckbox("女",false,sex);
box28=Box.createHorizontalBox();
box28.add(newLabel("性别:
"));
box28.add(box26);
box28.add(box27);
box210=Box.createHorizontalBox();
button21=newButton("录入");
button22=newButton("重置");
button21.addActionListener(this);
button22.addActionListener(this);
box210.add(button21);
box210.add(Box.createHorizontalStrut(10));
box210.add(button22);
box29=Box.createVerticalBox();
box29.add(Box.createVerticalStrut(10));
box29.add(box21);
box29.add(Box.createVerticalStrut(8));
box29.add(box22);
box29.add(Box.createVerticalStrut(8));
box29.add(box28);
box29.add(Box.createVerticalStrut(8));
box29.add(box23);
box29.add(Box.createVerticalStrut(8));
box29.add(box24);
box29.add(Box.createVerticalStrut(8));
box29.add(box25);
box29.add(Box.createVerticalStrut(80));
box29.add(box210);
add(box29);
setVisible(true);
}
publicvoidactionPerformed(ActionEvente)
{
Stringnumber1="";
number1=number.getText();
if(number1.length()>0)
{
try{
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
Shashtable=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exceptionee)
{System.out.println("创建散列表出现问题!
");}
}
if(Shashtable.containsKey(number1))
{
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)
{
Stringname1=name.getText();
Stringbanji1=banji.getText();
Stringzhuanye1=zhuanye.getText();
Stringdata1=data.getText();
Stringsex=null;
if(box26.getState())
{sex=box26.getLabel();}
else{sex=box27.getLabel();}
student=newStudent();
student.setNumber(number1);
student.setName(name1);
student.setbanji(banji1);
student.setzhuanye(zhuanye1);
student.setdata(data1);
student.setSex(sex);
try{
outOne=newFileOutputStream(file);
outTwo=newObjectOutputStream(outOne);
Shashtable.put(number1,student);
outTwo.writeObject(Shashtable);
outTwo.close();
outOne.close();
}
catch(Exceptionee){System.out.println("输出散列表出现问题!
");}
number.setText(null);
name.setText(null);
banji.setText(null);
zhuanye.setText(null);
data.setText(null);
}
}
}
}
(3)学生基本信息的查询功能
importjava.io.*;
importjava.util.Hashtable;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
classselectextendsPanelimplementsActionListener
{
RandomAccessFileout;
Boxbox31,box32,box33,box34,box35,box36,box37;
TextFieldnumber31,number32,number33,number34,number35;
Buttonbutton33;
Checkboxnan,nv;
CheckboxGroupsex31;
Filefile=null;
staticStudentstudent=null;
staticHashtableShashtable=null;
staticFileInputStreaminOne=null;
staticObjectInputStreaminTwo=null;
staticFileOutputStreamoutOne=null;
staticObjectOutputStreamoutTwo=null;
select()
{
box31=Box.createHorizontalBox();
box31.add(newLabel("需要查询的学号:
"));
number31=newTextField(10);
file=newFile("G:
\\","学生管理系统.txt");
Shashtable=newHashtable();
if(!
file.exists())
{
try
{
FileOutputStreamout=newFileOutputStream(file);
ObjectOutputStreamobjectOut=newObjectOutputStream(out);
objectOut.writeObject(Shashtable);
objectOut.close();
out.close();
}
catch(IOExceptione){}
}
button33=newButton("查询");
button33.addActionListener(this);
box31.add(number31);
box31.add(Box.createHorizontalStrut(10));
box31.add(button33);
box32=Box.createHorizontalBox();
box32.add(newLabel("姓名:
"));
number32=newTextField(20);
box32.add(number32);
sex31=newCheckboxGroup();
nan=newCheckbox("男",true,sex31);
nv=newCheckbox("女",false,sex31);
box33=Box.createHorizontalBox();
box33.add(newLabel("性别:
"));
box33.add(nan);
box33.add(nv);
box34=Box.createHorizontalBox();
box34.add(newLabel("专业:
"));
number33=newTextField(20);
box34.add(number33);
box35=Box.createHorizontalBox();
box35.add(newLabel("班级:
"));
number34=newTextField(20);
box35.add(number34);
box36=Box.createHorizontalBox();
box36.add(newLabel("出生:
"));
number35=newTextField(20);
box36.add(number35);
box37=Box.createVerticalBox();
box37.add(Box.createVerticalStrut(20));
box37.add(box31);
box37.add(Box.createVerticalStrut(8));
box37.add(box32);