java课程设计班级管理系统.docx
《java课程设计班级管理系统.docx》由会员分享,可在线阅读,更多相关《java课程设计班级管理系统.docx(37页珍藏版)》请在冰点文库上搜索。
java课程设计班级管理系统
Java课程设计
简单的班级管理系统
学院:
船山学院
2004-12-20
:
需求分析
1.功能需求
1).能够实现对班级学生基本资料的录入,包括学生的学号,姓名,性别,所学专业,家庭住址以及出生年月等。
2).能够实现对学生基本资料的修改。
3).根据学号对学生资料进行查询。
4).能够删除某些学生的资料。
:
总体设计
本班级管理系统共有6个java源文件。
类之间的主要关系如下图所示:
各主类的主要作用如下:
1).
该java文件的类负责创建班级学生管理系统的主窗口。
该类包含main方法,程序从
该类开始执行。
2).
该文件的类负责创建班级学生管理系统的学生信息录入界面。
3).
该文件的类负责创建班级学生管理系统的学生基本信息修改界面。
4).
该文件的类负责创建班级学生管理系统的学生基本信息查询界面。
5).
该文件的类负责创建班级学生管理系统的学生信息删除界面。
6).
负责创建存放学生信息的对象。
三:
详细设计
1.主类
1).成员变量
主要成员变量
成员变量描述
变量类型
变量名称
基本信息录入界面
StudentSituation
基本信息录入
基本信息修改界面
ModifySituation
基本信息修改
基本信息查询界面
Inquest
基本信息查询
基本信息删除界面
Delete
基本信息删除
菜单选项
JMenultem
录入,修改,查询,删除
存基本信息的散列表
Hashtable
基本信息
存放散列表的文件
File
file
2).方法
主要方法
名称
功能
备注
StudentManager
创建程序主窗口
构造方法
actionPerformed
处理ActionEvent事件
接口方法
main
程序开始运行
3).代码
import.*;
import.*;
import.*;
implements
importclassStudentManagerextendsJFrame
ActionListener
{
StudentSituation
基本信息录入=null;
ModifySituation
基本信息修改
=null;
Inquest
基本信息查询
=null;
Delete
基本信息删除
=null;
JMenuBarbar;
JMenufileMenu;
JMenuItem录入,修改,查询,删除,退出
Containercon=null;
Hashtable基本信息=null;
Filefile=null;
CardLayoutcard=null;
JLabellabel;
JPanelpCenter;
publicStudentManager()
{
setTitle("欢迎进入班级管理系统");
录入=newJMenuItem("录入学生基本信息");
修改=newJMenuItem("修改学生基本信息");
查询=newJMenuItem("查询学生基本信息");
删除=newJMenuItem("删除学生基本信息");
退出=newJMenuItem("退出本系统");
退出.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEventevent)
{
(0);
}
});
bar=newJMenuBar();
fileMenu=newJMenu("菜单选项");
(录入);
();
(修改);
();
(查询);
();
(删除);
();
();
(退出);
(fileMenu);
setJMenuBar(bar);
label=newJLabel("欢迎进入班级管理系统!
",;
(newFont("隶书",,30));
J
基本信息=newHashtable();
录入.addActionListener(this);
修改.addActionListener(this);
查询.addActionListener(this);
删除.addActionListener(this);
card=newCardLayout();
con=getContentPane();
pCenter=newJPanel();
(card);
file=newFile("学生基本信息.txt");
if(!
())
{
try{
FileOutputStreamout=newFileOutputStream(file);
ObjectOutputStreamobjectOut=new
ObjectOutputStream(out);
(基本信息);
();
();
}
catch(IOExceptione)
{
}
}
基本信息录入=newStudentSituation(file);
基本信息修改=newModifySituation(file);
基本信息查询=newInquest(this,file);
基本信息删除=newDelete(file);
("欢迎语界面",label);
("录入界面",基本信息录入);
("修改界面",基本信息修改);
("删除界面",基本信息删除);
(pCenter,;
();
addWindowListener(newWindowAdapter()
{publicvoidwindowClosing(WindowEvente){
(0);
}
});
setVisible(true);
setBounds(100,50,420,380);
validate();
}
publicvoidactionPerformed(ActionEvente)
{
if()==录入)
{
(pCenter,"录入界面");
}
elseif()==修改)
{
(pCenter,"修改界面");
}
elseif()==查询)
基本信息查询.setVisible(true);
}
elseif()==删除)
{
(pCenter,"删除界面");
}
}
publicstaticvoidmain(Stringargs[])
{
newStudentManager();
}
}
2.录入界面
1).成员变量
主要成员变量属性
描述
变量类型
变量名称
存放“学生”对象的散列表
Hashtable
基本信息表
输入学生基本信息的文本
JTextField
学号,姓名,所学专业,家庭
存放学生信息的对象
Student
住址,出生
学生
2).方法
主要方法
名称
功能
备注
StudentSituation
创建学生信息录入界面
构造方法
actionPeformed
处理ActionEvent事件
接口方法
3).代码import.*;
import.*;
import.*;
import.*;
publicclassStudentSituationextendsJPanelimplementsActionListener{
Hashtable基本信息表=null;
JTextField学号,姓名,所学专业,家庭住址,出生;
JRadioButton男,女;
Student学生=null;
ButtonGroupgroup=null;
JButton录入,重置;
FileInputStreaminOne=null;
ObjectInputStreaminTwo=null;
FileOutputStreamoutOne=null;
ObjectOutputStreamoutTwo=nuII;
Filefile=nuII;
publicStudentSituation(Filefile)
{
=file;
学号=newJTextField(10);
姓名=newJTextField(10);
所学专业=newJTextField(10);
WM审卑Hi
圧舟"newJTexmie-duo)八groupunewBuxonGroupo八迪"newJRadioBuffon(=迪==rue)八
HunewJRadioBUs:
on(=H=fa-se=(手
(H=
知>"newJBU=on(=知>=)八Hw"newJBU=on(=Hw=)八知>.addACHOnLisCDneahis)八Hw.addACHOnLisCDneahis)八
Boxboxl")八
(newJLabe_(=<4:
==
Boxbox2")八(newJLabe-(=(辱役=
Boxbox3")八(newJLabe-(=(手
(H=
Boxbox4")八(newJLabe-(=(Kfe-)-
Boxbox5")八(newJLabe-(=(WM审卑)-
Boxbox6=();
(newJLabel("出生:
",);
(出生);
BoxboxH=();
(box1);
(box2);
(box3);
(box4);
(box5);
(box6);
());
JPanelpCenter=newJPanel();
(boxH);
setLayout(newBorderLayout());
add(pCenter,;
JPanelpSouth=newJPanel();
(录入);
(重置);
add(pSouth,;
validate();
}
publicvoidactionPerformed(ActionEvente)
{
if()==录入)
{
Stringnumber="";
if()>0)
{
try{
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
基本信息表=(Hashtable)();
();
();
}
catch(Exceptionee)
{
}
if(基本信息表.containsKey(number))
{
Stringwarning="
该生基本信息已存在,请到修改页面修改!
";
(this,warning,
Ah.h.
警告",;
}
else
基本信息将被录入!
";
姓名.getText();
所学专业.getText();
{
Stringm="intok=(this,m,"确认",,;
if(ok==
{
Stringname=
Stringdiscipling=
Stringborth=
出生.getText();
Stringsex=null;
if(男.isSelected())
{
sex=男.getText();
}
else
{
sex=女.getText();
}
学生=newStudent();
学生.setNumber(number);
学生.setName(name);
学生.setDiscipling(discipling);
学生.setGrade(grade);
学生.setBorth(borth);
学生.setSex(sex);
try{
outOne=newFileOutputStream(file);
outTwo=newObjectOutputStream(outOne);
基本信息表.put(number,学生);
(基本信息表);
();
();
学号.setText(null);
姓名.setText(null);
家庭住址.setText(null);
出生.setText(null);
catch(Exceptionee)
{
}
}
}
}
else
{
(this,warning,"
Ah.h.
警告",;
Stringwarning="
必须要输入学号!
";
}
}
重置)
if()==
{
学号.setText(null);姓名.setText(null);
所学专业.setText(null);
家庭住址.setText(null);出生.setText(null);
3.查询界面
1).成员变量
主要成员变量属性
描述
变量类型
变量名称
存放“学生”对象的散表
Hashtable
基本信息表
显示学生基本信息的文本
JTextField
学号,姓名,所学专业,家庭住
址,出生
2).方法
主要方法
名称
功能
备注
Inquest
创建杳询界面
构造方法
actionPeformed
处理ActionEvent事件
接口方法
3).代码
import.*;
import.*;
import.*;
import.*;
publicclassInquestextendsJDialogimplementsActionListener
{
Hashtable基本信息表=null;
JTextField学号,姓名,所学专业,家庭住址,出生;
JRadioButton男,女;
JButton查询;
ButtonGroupgroup=null;
FileInputStreaminOne=null;
0bjecHnpufs=reaminTwounu=F=efi-eunu=pub=c-nquesf(JFramefzl-efi-e)宀
super(f=1<违^®^=fa-se=
Hfi-p
<4"newJTexmie-duo)八1<违"newJBU=on(=1<违=)八<4addACHOnusCDneahis)八1<违.addACHOnLisCDneahis)八辱役"newJTexmie-duo)八辱役.sefTidiQrb-e(fa-se)八
淳<4^"newJTexmie-duo)八
淳<4^.semdifab-eua-se)八
WM审卑Hi
wM^it.semdifab-eua-se)八圧舟"newJTexmie-duo)八圧并.sefTidiQrb-e(fa-se)八迪"newJRadioBuffon(=迪=fa-se)八HunewJRadioBUs:
on(=H=fa-se)八groupunewBuxonGroupo八(手(H=
Boxboxl")八
(newJLabe-(=鸯>^[<违孚<4■■_-)(<4=
([<违=
Boxbox2")八
(newJLabe-(=
(
Boxbox3")八(newJLabe-(=(手
(H=
Boxbox4")八(newJLabe-(=(淳<4乏X
Boxbox5")八(newJLabe-(=(WM亠卅卑X
Boxbox6")八
(newJLabe-(=圧卄■■_-)八
(圧舟)-
BoxboxH")八
(boxD
(box2=
(box3)八
(box4)八
(box5)八
(box6)八
())-
Jpane-pcenCDrunewJpaneo
(boxH)八
containerconugefconCDnfpaneo-
(pcenCDr」
()-
sefsesoundsu002000060270)八addwindowusCDnesewwindowAdapCDro宀pub=cvoidwindowcosingo/vindowEvenfe)宀
sefpub=cvoidacnonperformed(AcnonEvenfe)
辱役.sefrexsuw八淳<4^.sefrexsM-)八wM^it.sefrexsM-)八圧舟.sefrexsuw八=h(Hu[<违__(llu<4)
宀
SiringnumberuJnumber"<4.gefrexo
=h()vo)
宀
fry宀
inoneunewF=e-npufs=ream(fi-e)八inTwounewobjecHnpufs=ream(inone)八
基本信息表=(Hashtable)();
();
();
}
catch(Exceptionee)
{
}
if(基本信息表.containsKey(number))
{
Studentstu=(Student)基本信息表.get(number);
姓名.setText());
所学专业.setText());
家庭住址.setText());
出生.setText());
if().equals("男"))
{
男.setSelected(true);
}
else
{
女.setSelected(true);
}
}
else
该学号不存在!
";
{
/n.
警告",;
Stringwarning="
(this,warning,"
}
}
else
必须要输入学号!
";
+II.警告,;
{
Stringwarning="
(this,warning,"
}
}
}
}
3.修改界面
1).成员变量
主要成员变量
描述
变量类型
变量名称
存放“学生”对象的散列表
Hashtabel
基本信息表
输入学生基本信息的文本条
JTextField
学号,姓名,所学专业,家庭
住址,出生
2).方法
主要方法
名称
功能
备注
ModifySituation
创建学生信息修改界面
构造方法
actionPerform
处理ActionEvent事件
接口方法
3).代码
import.*;
import.*;
import.*;
import.*;
publicclassModifySituationextendsJPanelimplementsActionListener{
Hashtable基本信息表=null;
JTextField学号,姓名,所学专业,家庭住址,出生;
JRadioButton男,女;
ButtonGroupgroup=null;
JButton开始修改,录入修改,重置;
FileInputStreaminOne=null;
ObjectInputStreaminTwo=null;
FileOutputStreamoutOne=null;
ObjectOutputStreamoutTwo=null;
Filefile=null;
publicModifySituation(Filefile)
{
=file;
学号=newJTextField(10);
姓名=newJTextField(10);
所学专业=newJTextField(10);
家庭住址=newJTextField(10);
出生=newJTextField(10);
group=newButtonGroup();
男=newJRadioButton("男",true);
女=newJRadioButton("女",false);
(男);
(女);
开始修改=newJButton("开始修改");
录入修改=newJButton("录入修改");
录入修改.setEnabled(false);
重置=newJButton("重置");
学号.addActionListener(this);
开始修改.addActionListener(this);
录入修改.addActionListener(this);
重置.addActionListener(this);
Boxbox1=();
(newJLabel("输入要修改信息的学号:
",);
(学号);
(开始修改);
Boxbox2=();
(newJLabel("(新)姓名:
",);
(姓名);
Boxbox3=();
(newJLabel("(新)性别:
",);
(男);
(女);
Boxbox4=();
(newJLabel("(新)所学专业:
",);
(所学专业);
Boxbox5=();
(newJLabel("(新)家庭住址:
",);
(家庭住址);
Boxbox6=();
(出生);
BoxboxH=();
(box1);
(box2);
(box3);
(box4);
(box5);
(box6);
());
JPanelpCenter=newJPanel();
(boxH);
setLayout(newBorderLayout());
add(pCenter,;
JPanelpSouth=newJPanel();
(录入修改);
(重置);
add(pSouth,;
validate();
}
publicvoidactionPerformed(ActionEvente)
{
if()==开始修改||()==学号)
{
Stringnumber="";
number=学号.getText();
aVo)
宀
fry宀
inoneunewF=e-npufs=ream(fi-e)八inTwounewobjecHnpufs=ream(inone)八
mMaw>"HashfabCDp
()-
()-
caoh(Excep=*onee)
宀
if(mMap®>oonQrinsKey(number))
知>克齊.semnab-edarue)八
Sfudenfsc"scdenomMaw>.gesumber)-辱役.sefrexo)八
^<4w