学生信息管理系统Word文件下载.docx
- 文档编号:21293970
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:22
- 大小:21.56KB
学生信息管理系统Word文件下载.docx
《学生信息管理系统Word文件下载.docx》由会员分享,可在线阅读,更多相关《学生信息管理系统Word文件下载.docx(22页珍藏版)》请在冰豆网上搜索。
修
改
学生信息管理
添
加
找
3.各模块的功能及程序说明:
(1)导入所需要的类包
代码:
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjava.io.*;
importjava.util.*;
(2)Menuactions类的编写:
classStudentimplementsjava.io.Serializable{
Stringnumber,name,specialty,grade,borth,sex;
publicStudent(){};
publicvoidsetNumber(Stringnumber){this.number=number;
}
publicStringgetNumber(){returnnumber;
publicvoidsetName(Stringname){this.name=name;
publicStringgetName(){returnname;
publicvoidsetSex(Stringsex){this.sex=sex;
publicStringgetSex(){returnsex;
publicvoidsetSpecialty(String
specialty){this.specialty=specialty;
publicStringgetSpecialty(){returnspecialty;
publicvoidsetGrade(Stringgrade){this.grade=grade;
publicStringgetGrade(){returngrade;
publicvoidsetBorth(Stringborth){this.borth=borth;
publicStringgetBorth(){returnborth;
(3)录入学生信息部分:
publicclassStudentManagerextendsJFrame{
JLabellb=newJLabel("
录入请先输入记录,查询、删除请先输入学号,修改是对查
询"
+
"
内容改后的保存!
);
JTextField学号,姓名,专业,年级,出生;
JRadioButton男,女;
ButtonGroupgroup=null;
JButton录入,查询,删除,修改,显示;
JPanelp1,p2,p3,p4,p5,p6,pv,ph;
Student学生=null;
Hashtable学生散列表=null;
Filefile=null;
FileInputStreaminOne=null;
ObjectInputStreaminTwo=null;
FileOutputStreamoutOne=null;
ObjectOutputStreamoutTwo=null;
publicStudentManager(){
super("
学生基本信息管理系统"
学号=newJTextField(10);
姓名=newJTextField(10);
专业=newJTextField(10);
年级=newJTextField(10);
出生=newJTextField(10);
group=newButtonGroup();
男=newJRadioButton("
男"
true);
女=newJRadioButton("
女"
false);
group.add(男);
group.add(女);
录入=newJButton("
录入"
查询=newJButton("
查询"
删除=newJButton("
删除"
修改=newJButton("
修改"
显示=newJButton("
显示"
录入.addActionListener(newInputAct());
查询.addActionListener(newInquestAct());
修改.addActionListener(newModifyAct());
删除.addActionListener(newDeleteAct());
显示.addActionListener(newShowAct());
修改.setEnabled(false);
p1=newJPanel();
p1.add(newJLabel("
学号:
JLabel.CENTER));
p1.add(学号);
p2=newJPanel();
p2.add(newJLabel("
姓名:
p2.add(姓名);
p3=newJPanel();
p3.add(newJLabel("
性别:
p3.add(男);
p3.add(女);
p4=newJPanel();
p4.add(newJLabel("
专业:
p4.add(专业);
p5=newJPanel();
p5.add(newJLabel("
年级:
p5.add(年级);
p6=newJPanel();
p6.add(newJLabel("
出生:
p6.add(出生);
pv=newJPanel();
pv.setLayout(newGridLayout(6,1));
pv.add(p1);
pv.add(p2);
pv.add(p3);
pv.add(p4);
pv.add(p5);
pv.add(p6);
ph=newJPanel();
ph.add(录入);
ph.add(查询);
ph.add(修改);
ph.add(删除);
ph.add(显示);
file=newFile("
学生信息.txt"
学生散列表=newHashtable();
if(!
file.exists()){
try{
FileOutputStreamout=newFileOutputStream(file);
ObjectOutputStreamobjectOut=newObjectOutputStream(out);
objectOut.writeObject(学生散列表);
objectOut.close();
out.close();
catch(IOExceptione){}
Containercon=getContentPane();
con.setLayout(newBorderLayout());
con.add(lb,BorderLayout.NORTH);
con.add(pv,BorderLayout.CENTER);
con.add(ph,BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(100,100,600,300);
setVisible(true);
显示对话框的设计:
classStudentShowextendsJDialog{
Hashtable学生散列表=null;
JTextArea显示=null;
publicStudentShow(Filefile){
super(newJFrame(),"
显示对话框"
this.file=file;
显示=newJTextArea(16,30);
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
学生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
catch(Exceptionee){}
if(学生散列表.isEmpty())显示.append("
目前还没有学生的信息记录!
\n"
else{
显示.setText("
学号姓名性别专业年级出生\n"
for(Enumerationenm=学生散列
表.elements();
enm.hasMoreElements();
){
Studentstu=(Student)enm.nextElement();
Stringsex="
;
if(stu.getSex().equals("
))sex="
elsesex="
String
str=stu.getNumber()+"
"
+stu.getName()+"
+sex+"
+stu.getSpecialty()+"
+stu.getGrade()+"
+stu.getBorth()+"
显示.append(str);
JScrollPanescroll=newJScrollPane(显示);
con.add("
Center"
scroll);
con.validate();
setBounds(200,200,400,300);
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvent
e){setVisible(false);
4.源程序:
publicstaticvoidmain(String[]args){newStudentManager();
classInputActimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
Stringnumber="
number=学号.getText();
if(number.length()>
0){
catch(Exceptionee){System.out.println("
创建散列表出现问题!
if(学生散列表.containsKey(number)){
Stringwarning="
该生信息已存在,请到修改页面修改!
JOptionPane.showMessageDialog(null,warning,"
警告"
JOptionPane.WARNING_MESSAGE);
}//endif1
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();
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);
}//endelse1
}//endif0
必须输入学号!
JOptionPane.showMessageDialog(null,warning,
JOptionPane.WARNING_MESSAGE);
}//endelse0
}//endactionPerformed
}//endclass
classInquestActimplementsActionListener{
散列表有问题!
修改.setEnabled(true);
Studentstu=(Student)学生散列表.get(number);
姓名
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 信息管理 系统