java课程设计(班级管理系统)_第1页
java课程设计(班级管理系统)_第2页
java课程设计(班级管理系统)_第3页
java课程设计(班级管理系统)_第4页
java课程设计(班级管理系统)_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Java课程设计-简单的班级管理系统学院:船山学院 班级:计算机029班姓名: 陈 强 学号: 2004-12-20一:需求分析1.功能需求1).能够实现对班级学生基本资料的录入,包括学生的学号,姓名,性别,所学专业,家庭住址以及出生年月等。2).能够实现对学生基本资料的修改。3).根据学号对学生资料进行查询。4).能够删除某些学生的资料。二:总体设计 本班级管理系统共有6个java源文件。类之间的主要关系如下图所示: StudentManager(主类)DeleteStudentStudentSituationModiifySituationInquest各主类的主要作用如下:1).Stud

2、entManager.java该java文件的类负责创建班级学生管理系统的主窗口。该类包含main方法,程序从该类开始执行。2).StudentStituation.java该文件的类负责创建班级学生管理系统的学生信息录入界面。3).ModifySituation.java该文件的类负责创建班级学生管理系统的学生基本信息修改界面。4).Inquest.java该文件的类负责创建班级学生管理系统的学生基本信息查询界面。5).Delete.java该文件的类负责创建班级学生管理系统的学生信息删除界面。6).Student.java负责创建存放学生信息的对象。三:详细设计1 主类StudentMan

3、ager.java1).成员变量主要成员变量成员变量描述变量类型变量名称基本信息录入界面基本信息修改界面基本信息查询界面基本信息删除界面菜单选项 存基本信息的散列表存放散列表的文件StudentSituationModifySituationInquestDeleteJMenuItemHashtableFile基本信息录入基本信息修改基本信息查询基本信息删除录入,修改,查询,删除基本信息file2).方法主要方法名称功能备注StudentManageractionPerformedmain创建程序主窗口 处理ActionEvent事件程序开始运行构造方法接口方法3).代码StudentMana

4、ger.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Hashtable;public class StudentManager extends JFrame implements ActionListener StudentSituation 基本信息录入=null; ModifySituation 基本信息修改=null; Inquest 基本信息查询=null; Delete 基本信息删除=null; JMenuBar bar; JM

5、enu fileMenu; JMenuItem 录入,修改,查询,删除,退出; Container con=null; Hashtable 基本信息=null; File file=null; CardLayout card=null; JLabel label; JPanel pCenter; public StudentManager() setTitle(欢迎进入班级管理系统); 录入=new JMenuItem(录入学生基本信息); 修改=new JMenuItem(修改学生基本信息); 查询=new JMenuItem(查询学生基本信息); 删除=new JMenuItem(删除学生

6、基本信息); 退出=new JMenuItem(退出本系统); 退出.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) System.exit(0); ); bar=new JMenuBar(); fileMenu=new JMenu(菜单选项); fileMenu.add(录入); fileMenu.addSeparator(); fileMenu.add(修改); fileMenu.addSeparator(); fileMenu.add(查询); fileMenu.a

7、ddSeparator(); fileMenu.add(删除); fileMenu.addSeparator(); fileMenu.addSeparator(); fileMenu.add(退出); bar.add(fileMenu); setJMenuBar(bar); label=new JLabel(欢迎进入班级管理系统!,label.CENTER); label.setFont(new Font(隶书,Font.BOLD,30); label.setForeground(Color.blue); 基本信息=new Hashtable(); 录入.addActionListener(t

8、his); 修改.addActionListener(this); 查询.addActionListener(this); 删除.addActionListener(this); card=new CardLayout(); con=getContentPane(); pCenter=new JPanel(); pCenter.setLayout(card); file=new File(学生基本信息.txt); if(!file.exists() try FileOutputStream out=new FileOutputStream(file); ObjectOutputStreamob

9、jectOut=new ObjectOutputStream(out); objectOut.writeObject(基本信息); objectOut.close(); out.close(); catch(IOException e) 基本信息录入=new StudentSituation(file); 基本信息修改=new ModifySituation(file); 基本信息查询=new Inquest(this,file); 基本信息删除=new Delete(file); pCenter.add(欢迎语界面,label); pCenter.add(录入界面,基本信息录入); pCen

10、ter.add(修改界面,基本信息修改); pCenter.add(删除界面,基本信息删除); con.add(pCenter,BorderLayout.CENTER); con.validate(); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); setVisible(true); setBounds(100,50,420,380); validate(); public void actionPerformed(ActionEvent e)

11、if(e.getSource()=录入) card.show(pCenter,录入界面); else if(e.getSource()=修改) card.show(pCenter,修改界面); else if(e.getSource()=查询) 基本信息查询.setVisible(true); else if(e.getSource()=删除) card.show(pCenter,删除界面); public static void main(String args) new StudentManager(); 2.录入界面1).成员变量主要成员变量属性描述变量类型变量名称存放“学生”对象的散列

12、表输入学生基本信息的文本存放学生信息的对象HashtableJTextFieldStudent基本信息表学号,姓名,所学专业,家庭住址,出生学生2).方法主要方法名称功能备注StudentSituationactionPerformed创建学生信息录入界面处理ActionEvent事件构造方法接口方法3).代码StudentSituation.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class StudentSitu

13、ation extends JPanel implements ActionListener Hashtable 基本信息表=null; JTextField 学号,姓名,所学专业,家庭住址,出生; JRadioButton 男,女; Student 学生=null; ButtonGroup group=null; JButton 录入,重置; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File f

14、ile=null; public StudentSituation(File file) this.file=file; 学号=new JTextField(10); 姓名=new JTextField(10); 所学专业=new JTextField(10); 家庭住址=new JTextField(10); 出生=new JTextField(10); group=new ButtonGroup(); 男=new JRadioButton(男,true); 女=new JRadioButton(女,false); group.add(男); group.add(女); 录入=new JBu

15、tton(录入); 重置=new JButton(重置); 录入.addActionListener(this); 重置.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel(学号:,JLabel.CENTER); box1.add(学号); Box box2=Box.createHorizontalBox(); box2.add(new JLabel(姓名:,JLabel.CENTER); box2.add(姓名); Box box3=Box.createHorizontalBox()

16、; box3.add(new JLabel(性别:,JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(new JLabel(所学专业:,JLabel.CENTER); box4.add(所学专业); Box box5=Box.createHorizontalBox(); box5.add(new JLabel(家庭住址:,JLabel.CENTER); box5.add(家庭住址); Box box6=Box.createHorizontalBox(); box6.add

17、(new JLabel(出生:,JLabel.CENTER); box6.add(出生); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(new BorderLayout(); add(pCenter

18、,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(录入); pSouth.add(重置); add(pSouth,BorderLayout.SOUTH); validate(); public void actionPerformed(ActionEvent e) if(e.getSource()=录入) String number=; number=学号.getText(); if(number.length()0) try inOne=new FileInputStream(file); inTwo=new Obje

19、ctInputStream(inOne); 基本信息表=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee) if(基本信息表.containsKey(number) String warning=该生基本信息已存在,请到修改页面修改!; JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE); else String m=基本信息将被录入!; intok=JOptionPane.showCon

20、firmDialog(this,m,确认,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(ok=JOptionPane.YES_OPTION) String name=姓名.getText(); String discipling=所学专业.getText(); String grade=家庭住址.getText(); String borth=出生.getText(); String sex=null; if(男.isSelected() sex=男.getText(); else sex=女.getText();

21、 学生=new Student(); 学生.setNumber(number); 学生.setName(name); 学生.setDiscipling(discipling); 学生.setGrade(grade); 学生.setBorth(borth); 学生.setSex(sex); try outOne=new FileOutputStream(file); outTwo=new ObjectOutputStream(outOne); 基本信息表.put(number,学生); outTwo.writeObject(基本信息表); outTwo.close(); outOne.close

22、(); 学号.setText(null); 姓名.setText(null); 所学专业.setText(null); 家庭住址.setText(null); 出生.setText(null); catch(Exception ee) System.out.println(ee); else String warning=必须要输入学号!; JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE); if(e.getSource()=重置) 学号.setText(null); 姓名.setText(nu

23、ll); 所学专业.setText(null); 家庭住址.setText(null); 出生.setText(null); 3.查询界面1).成员变量主要成员变量属性描述变量类型变量名称存放“学生”对象的散表显示学生基本信息的文本HashtableJTextField基本信息表学号,姓名,所学专业,家庭住址,出生2).方法主要方法名称功能备注InquestactionPerformed创建查询界面处理ActionEvent事件构造方法接口方法3).代码Inquest.javaimport java.awt.*;import java.awt.event.*;import javax.swin

24、g.*;import java.io.*;import java.util.*;public class Inquest extends JDialog implements ActionListener Hashtable 基本信息表=null; JTextField 学号,姓名,所学专业,家庭住址,出生; JRadioButton 男,女; JButton 查询; ButtonGroup group=null; FileInputStream inOne=null; ObjectInputStream inTwo=null; File file=null; public Inquest(J

25、Frame f,File file) super(f,查询对话框,false); this.file=file; 学号=new JTextField(10); 查询=new JButton(查询); 学号.addActionListener(this); 查询.addActionListener(this); 姓名=new JTextField(10); 姓名.setEditable(false); 所学专业=new JTextField(10); 所学专业.setEditable(false); 家庭住址=new JTextField(10); 家庭住址.setEditable(false)

26、; 出生=new JTextField(10); 出生.setEditable(false); 男=new JRadioButton(男,false); 女=new JRadioButton(女,false); group=new ButtonGroup(); group.add(男); group.add(女); Box box1=Box.createHorizontalBox(); box1.add(new JLabel(输入要查询的学号:,JLabel.CENTER); box1.add(学号); box1.add(查询); Box box2=Box.createHorizontalBo

27、x(); box2.add(new JLabel(姓名:,JLabel.CENTER); box2.add(姓名); Box box3=Box.createHorizontalBox(); box3.add(new JLabel(性别:,JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(new JLabel(所学专业:,JLabel.CENTER); box4.add(所学专业); Box box5=Box.createHorizontalBox(); box5.add(

28、new JLabel(家庭住址:,JLabel.CENTER); box5.add(家庭住址); Box box6=Box.createHorizontalBox(); box6.add(new JLabel(出生:,JLabel.CENTER); box6.add(出生); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue

29、(); JPanel pCenter=new JPanel(); pCenter.add(boxH); Container con=getContentPane(); con.add(pCenter,BorderLayout.CENTER); con.validate(); setVisible(false); setBounds(100,200,360,270); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) setVisible(false); ); public void ac

30、tionPerformed(ActionEvent e) 姓名.setText(null); 所学专业.setText(null); 家庭住址.setText(null); 出生.setText(null); if(e.getSource()=查询|e.getSource()=学号) String number=; number=学号.getText(); if(number.length()0) try inOne=new FileInputStream(file); inTwo=new ObjectInputStream(inOne); 基本信息表=(Hashtable)inTwo.rea

31、dObject(); inOne.close(); inTwo.close(); catch(Exception ee) if(基本信息表.containsKey(number) Student stu=(Student)基本信息表.get(number); 姓名.setText(stu.getName(); 所学专业.setText(stu.getDisciping(); 家庭住址.setText(stu.getGrade(); 出生.setText(stu.getBorth(); if(stu.getSex().equals(男) 男.setSelected(true); else 女.s

32、etSelected(true); else String warning=该学号不存在!; JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE); else String warning=必须要输入学号!; JOptionPane.showMessageDialog(this,warning,警告,JOptionPane.WARNING_MESSAGE); 3.修改界面1).成员变量主要成员变量描述变量类型变量名称存放“学生”对象的散列表输入学生基本信息的文本条HashtabelJTextFiel

33、d基本信息表学号,姓名,所学专业,家庭住址,出生2).方法主要方法名称功能备注ModifySituationactionPerform创建学生信息修改界面处理ActionEvent事件构造方法接口方法3).代码ModifySituation.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel implements ActionListener Hashta

34、ble 基本信息表=null; JTextField 学号,姓名,所学专业,家庭住址,出生; JRadioButton 男,女; ButtonGroup group=null; JButton 开始修改,录入修改,重置; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File file=null; public ModifySituation(File file) this.file=file; 学号=

35、new JTextField(10); 姓名=new JTextField(10); 所学专业=new JTextField(10); 家庭住址=new JTextField(10); 出生=new JTextField(10); group=new ButtonGroup(); 男=new JRadioButton(男,true); 女=new JRadioButton(女,false); group.add(男); group.add(女); 开始修改=new JButton(开始修改); 录入修改=new JButton(录入修改); 录入修改.setEnabled(false); 重置

36、=new JButton(重置); 学号.addActionListener(this); 开始修改.addActionListener(this); 录入修改.addActionListener(this); 重置.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel(输入要修改信息的学号:,JLabel.CENTER); box1.add(学号); box1.add(开始修改); Box box2=Box.createHorizontalBox(); box2.add(new JLa

37、bel(新)姓名:,JLabel.CENTER); box2.add(姓名); Box box3=Box.createHorizontalBox(); box3.add(new JLabel(新)性别:,JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(new JLabel(新)所学专业:,JLabel.CENTER); box4.add(所学专业); Box box5=Box.createHorizontalBox(); box5.add(new JLabel(新)家庭

38、住址:,JLabel.CENTER); box5.add(家庭住址); Box box6=Box.createHorizontalBox(); box6.add(new JLabel(新)出生:,JLabel.CENTER); box6.add(出生); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(new BorderLayout(); add(pCenter,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(录入修改); pSouth.add(重置); add(pSouth,BorderLayout.SOUTH

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论