您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页JAVAs学籍管理系统

JAVAs学籍管理系统

来源:华佗小知识


Java课程设计

基于数据结构的学籍管理系统

计算机科学与技术

学生姓名 xxx 班学

级 号

D计算机xx 13207043xx 刘骞

指导教师

目 录

1 课程设计及目的 ................................. 错误!未定义书签。 2 总体设计 ..................................... 错误!未定义书签。 2.1 专业.txt ..................................... 错误!未定义书签。 2.2 ManagerWindow类设计 .......................... 错误!未定义书签。 2.3 Student类设计 ................................ 错误!未定义书签。 2.4 StudentPicture类设计 ......................... 错误!未定义书签。 2.5 InputStudent类设计 ........................... 错误!未定义书签。 2.6 Inquest类设计 ................................ 错误!未定义书签。 2.7 ModifySituation类设计 ........................ 错误!未定义书签。 2.8 Delete类设计 ................................. 错误!未定义书签。 2.9 JavaClip类设计 ................................................. 2 3 ManagerWindow详细设计 ......................................... 2 4 Student详细设计 ............................................... 6 5 JavaClip详细设计 .............................................. 7 6 系统运行和调试 ................................................ 8 7 总结 ......................................................... 10 8 整体代码 ...................................................... 10

Java课程设计

基于数据结构的学籍管理系统的设计

1、

课程设计要求及目的

目的是通过课程设计的综合训练,培养学生实际分析问题、编程和动手能力,是学生对数据结构进行更深一层的了解。让同学们学会如何去查找资料和整合处理这些资料的能力,也为以后的大学毕业设计论文打下一个初步的基础。这个课程设计是比较难得,分成了几个部分,五个学生一组,通过讨论完成课程设计。培养团队协作精神;最终帮助学生系统掌握课程的主要内容,更好的完成教学任务。 设计基于数据结构的学籍管理系统的设计,具体要求如下:

(1) 录入学生基本信息功能的界面。用户可以通过菜单选项让程序呈现“录入

学生基本信息”功能的界面,通过该界面可以录入学生的学号、姓名、性别、出生日期、专业和照片等信息。

(2) 修改学生基本信息功能的界面。用户可以通过菜单选项让程序呈现“修改

学生基本信息”功能的界面,通过该界面可以对已录入的学生信息进行修改。

(3) 查询与打印学生基本信息功能的界面。用户可以通过菜单选项让程序呈现

“查询与打印学生基本信息”功能的界面,通过该界面,通过该界面可以对已录入的学生信息进行查询与打印。

(4) 删除学生基本信息功能的界面。用户可以通过菜单选项让程序呈现“删除

学生基本信息”功能的界面,通过该界面可以删除已录入的学生信息。

2、 总体设计

再设计学籍管理系统时,需要编写7个Java源文件:ManagerWindow.java、InputStudent.java、Inquest.java、ModifySituation.java、Delete.java、Student.java和StudentPicture.java。学籍管理系统除了需要编写的7个Java源文件所给出的类外,还需要Java系统提供的一些重要的类,如JMenuItem,HashMap和File等类。学籍管理系统所用到的一些重要的类以及之间的组合关系如下图: ManagerWindow InputStudenFile Delete HashMap Inquest ModifySituation JavaClip t StudentPicture StudentPicture StudentPicture Student

1

基于数据结构的学籍管理系统

2.1专业.txt

学籍管理系统通过使用名字为“专业.txt”的文本文件来生成专业名称列表,以便灵活、有效的录入专业信息。允许用户自己编写“专业.txt”文件,只要将该文件和应用程序存放到同一目录即可。 2.2 ManagerWindow.java(主类)

ManagerWindow类负责创建学籍管理系统的主窗口,该类含有main方法,程序从该类开始执行。ManagerWindow类的成员变量中有4种重要类型的对象:InputStudent、Inquest、ModifySituation和Delete对象。 2.3 Student.java

Student类所创建的对象是InputStudent类的成员之一,负责封装学生的基本信息。

2.4 StudentPicture.java

StudentPicture类所创建的对象是InputStuden、Inquest和ModifySituation类的成员之一,负责显示学生的照片。 2.5 InputStudent.java

InputStudent类创建的对象是ManagerWindow类的重要成员之一,负责提供录入学生基本信息的界面。 2.6 Inquest.java

Inquest类创建的对象是ManagerWindow类的重要成员之一,负责提供查询学生基本信息及打印基本信息的界面。 2.7 ModifySituation.java

ModifySituation类创建的对象是ManagerWindow类的重要成员之一,负责提供修改学生基本信息的界面。 2.8 Delete.java

Delete类创建的对象是ManagerWindow类的重要成员之一,提供删除学生基本信息的界面。 2.9 JavaClip.java

JavaClip类提供了程序背景音乐,可以在无聊的录入程序舒缓心情。

3、 ManagerWindow详细设计

1、效果图

2

Java课程设计

图(1)ManagerWindow创建的窗口在进行录入、修改和删除时的效果

2、UML图

ManagerWindow类是javax.swing包中JFrame的一个子类,并实现了ActionListener接口,标明该类的主要成员变量和方法的UML图。

JFrame ActionListener

ManagerWindow

基本信息录入:InputStudent

基本信息修改:ModifySituation

基本信息查询与打印:Inquest

基本信息删除:Delete

基本信息:HashMap

file:File

录入,修改,查询,删除,欢迎界面:JMenuItem

ManagerWindow():无类型

actionPerformed(ActionEvent):void

main(String):void

图(2)ManagerWindow类的UML图

3

基于数据结构的学籍管理系统

1) 成员变量

 “基本信息录入”是InputStudent对象,负责提供录入信息的界面。  “基本信息修改”是ModifySituation对象,负责提供修改信息的界

面.

 “基本信息查询与打印”是Inquest对象,负责提供查询与打印信息

的界面。

 “基本信息删除”是Delete对象,负责提供删除信息的界面。  “基本信息”是HashMap创建的散列映射,用于

存储键/值数据对,其中的键必须是一个String对象,键对应的值必须是Student对象。  File是File文件对象,程序将“基本信息”散列映射写入该文件中。  “录入”、“修改”、“查询”、“删除”、和“欢迎界面”是JMenuItem

创建的菜单项,这些菜单项都将当前窗口注册为自己的ActionEvent时间监视器。 2)方法

 ManagerWindow()是构造方法,负责完成窗口的初始化。

 actionPerformed(ActionEvent)方法是ManagerWindow类实现的

ActionListener接口中的方法。ManagerWindow创建的窗口是“录入” “修改”、“查询与打印”、“删除”和“欢迎界面”菜单项的ActionEvent事件监视器,当用户选择其中某个菜单项时,窗口将执行actionPerformed(ActionEvent)方法进行相应的操作。  main方法是程序运行的入口方法。 (3)代码如下

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.HashMap;

public class ManagerWindow extends JFrame implements ActionListener{

InputStudent 基本信息录入; ModifySituation 基本信息修改; Inquest 基本信息查询与打印; Delete 基本信息删除; JMenuBar bar; JMenu fileMenu;

JMenuItem 录入,修改,查询与打印,删除,欢迎界面;

File file=null; CardLayout card=null; JLabel label=null; JPanel pCenter; public ManagerWindow(){

录入=new JMenuItem(\"录入学生基本信息\");

修改=new JMenuItem(\"修改学生基本信息\");

查询与打印=new JMenuItem(\"查询与打印学生基本信息\");

删除=new JMenuItem(\"删除学生基本信息\");

欢迎界面=new JMenuItem(\"欢迎界面\"); bar=new JMenuBar();

fileMenu=new JMenu(\"菜单选项\"); fileMenu.add(录入); fileMenu.add(修改); fileMenu.add(查询与打印); fileMenu.add(删除); bar.add(fileMenu); setJMenuBar(bar);

label=new JLabel(\"学籍管理系统\

HashMap 基本信息=null; fileMenu.add(欢迎界面);

4

Java课程设计

label.setIcon(new ImageIcon(\"welcome.jpg\")); label.setFont(new Font(\"隶书\

label.setHorizontalTextPosition(SwingConst setBounds(100,50,460,280);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

addWindowListener(new WindowAdapter(){

ants.CENTER);

label.setForeground(Color.red); 基本信息=new

HashMap();

录入.addActionListener(this); 修改.addActionListener(this); 查询与打印.addActionListener(this); 删除.addActionListener(this); 欢迎界面.addActionListener(this); card=new CardLayout(); pCenter=new JPanel(); pCenter.setLayout(card); file=new File(\"基本信息.txt\"); if(!file.exists()){ try{

FileOutputStream out=new FileOutputStream(file);

ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(基本信息);

objectOut.close(); out.close(); }

catch(IOException e){} }

基本信息录入=new InputStudent(file); 基本信息修改=new ModifySituation(file);

基本信息查询与打印=new Inquest(file); 基本信息删除=new Delete(file); pCenter.add(\"欢迎界面\ pCenter.add(\"录入界面\基本信息录入); pCenter.add(\"修改界面\基本信息修改); pCenter.add(\"删除界面\基本信息删除); add(pCenter,BorderLayout.CENTER); validate(); setVisible(true);

public void windowClosing(WindowEvent e){ int

n=JOptionPane.showConfirmDialog(null,\"确认退出吗?\确认对话框\

JOptionPane.YES_NO_OPTION );

if(n==JOptionPane.YES_OPTION)

System.exit(0); }}); validate(); }

public void actionPerformed(ActionEvent e){

if(e.getSource()==录入){ 基本信息录入.clearMess(); card.show(pCenter,\"录入界面\"); }

else if(e.getSource()==修改){ 基本信息修改.clearMess(); card.show(pCenter,\"修改界面\"); }

else if(e.getSource()==查询与打印){ 基本信息查询与打印.clearMess(); 基本信息查询与打

印.setLocation(getBounds().x+getBounds().width,getBounds().y); 基本信息查询与打印.setVisible(true); }

else if(e.getSource()==删除) card.show(pCenter,\"删除界面\"); else if(e.getSource()==欢迎界面) card.show(pCenter,\"欢迎界面\"); }

public static void main(String args[]){ new ManagerWindow();

5

基于数据结构的学籍管理系统

JavaClip a=new JavaClip(); a.P(); }

}

4、Student类详细设计

1.效果图

Student创建的对象负责处理和学生有关的数据。没有可显示的效果图。 2.UML图

Student类创建的对象“学生”是InputStudent的重要成员之一,负责处理和学生有关的数据。标明Student类的主要成员变量和方法以及和InputStudent类之间组合关系的UML图。

Student Number,name,discipling,grade,borth,sex:String imagePic:File InputStudent 学生:Student setNumber(String):void getNumber():String setImagePic(File):void getImagePic():File

图(3)Student类的UML图

以下是UML图中有关数据和方法的详细说明。 成员变量

 number.name.discipling.grade.borth和sex是String对象,它们

的值分别表示学生的“学号”、“姓名”、“专业”、“年级”、“出生日期”和“性别”。

 imagePic是File对象,用于存放学生的照片图像的引用。 方法

 setNumber(String)和gerNumber()方法分别用来设置number和获取

number的值。

 setImagerPic(File)和gerImagPic()方法分别用来设置imagePic和

获取imagePic的引用。

代码(Student.java):

import java.io.*;

public class Student implements Serializable{ String

number,name,discipling,grade,borth,sex; File imagePic;

public void setNumber(String number){ this.number=number; }

public String getNumber(){ return number; }

6

Java课程设计

public void setName(String name){ this.name=name; }

public String getName(){ return name; }

public void setDiscipling(String discipling){

this.discipling=discipling; }

public String getDisciping(){ return discipling; }

public void setGrade(String grade){ this.grade=grade; }

public String getGrade(){ return grade; }

public void setBorth(String borth){ this.borth=borth; }

public String getBorth(){ return borth; }

public void setSex(String sex){ this.sex=sex; }

public String getSex(){ return sex; }

public void setImagePic(File image){ imagePic=image; }

public File getImagePic(){ return imagePic; } }

5、JavaClip类详细设计

效果图:

JavaClip类实现的是背景音乐的播放,没有效果图。 代码:

import java.applet.AudioClip; import java.io.*; import java.applet.Applet; import java.awt.Frame;

import java.net.MalformedURLException; import java.net.URL;

public class JavaClip extends Frame{ public JavaClip(){ super(); }

public void P() { try { URL cb; File f = new

File(\"E:\\\\chaper10\\\\123456.wav\"); //引号里面的是音乐文件所在的绝对鹿筋 cb = f.toURL(); AudioClip aau;

aau = Applet.newAudioClip(cb); //aau.play(); aau.loop();

//循环播放 aau.play() 单曲 aau.stop()停止播放

JavaClip frame=new JavaClip(); //frame.setBounds(0, 0, 300, 200); //frame.setVisible(true);

} catch (MalformedURLException e) { e.printStackTrace(); } } }

7

基于数据结构的学籍管理系统

6、系统运行与调试

整个学籍管理系统使用了jdka.6版本调试和运行。运行过程如下: (1) 运行主类出现如下图片:

然后单击菜单选项-录入学生基本信息出现如下图片;

单击录入-确认录入:

8

Java课程设计

单击菜单选项-修改学生基本信息:

单击开始修改,修改你要修改的内容,录入修改:

单击菜单选项-查询与打印学生基本信息:

9

基于数据结构的学籍管理系统

单击删除学生信息:

7、总结

一周的课程设计很快结束了,从中收获了很多的知识和快乐。对于Java这门语言,其实还是了解的太少,虽然上了一学期的课,但是学的是基础的知识,可是说是沧海一粟,所以面对课程设计这个大骨头,着实让我们措手不及。虽然书上有源代码,但是从书上到电脑上就是一个很大的工程,可能是我打过最多的一次吧!然后就是痛苦的调试代码阶段,因为是手打的代码,所以错误是层出不穷,在经历了千辛万苦过后,在代码运行成功的时候,我们几个都笑的很开心,感觉自己的辛苦没有白费,心里似乎还有一点点小小的自豪,虽然代码是书上的吧,但是也是我们一步一步弄出来的。大家的不放弃,互相鼓励,也让我感受到了一个team的精神。

然后就是大家分析代码的阶段,就相当于一群四级都没过的孩子,在看英语六级试卷,百度成了我们的唯一看的懂的东西,终于在大家的努力下,看懂了大概的原理。

总之,这次课程设计使我收获很多、学会很多、比以往更有耐心很多。感谢学校及老师给我们这次课程设计的机会,最真挚的感谢我们的辅导老师 ,在设计过程中,老师精心的辅导和不厌其烦地的态度才使得我们以顺利的完成这次设计,他那无私的奉献的精神照耀着我们对学习的热爱,同时也增加我们对知识的追求和欲望度。

8、整体代码

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.HashMap;

public class ManagerWindow extends JFrame implements ActionListener{

InputStudent 基本信息录入; ModifySituation 基本信息修改;

Inquest 基本信息查询与打印; Delete 基本信息删除; JMenuBar bar; JMenu fileMenu;

JMenuItem 录入,修改,查询与打印,删除,欢迎界面;

HashMap 基本信息=null; File file=null; CardLayout card=null;

10

Java课程设计

JLabel label=null; objectOut.writeObject(基本信 JPanel pCenter; public ManagerWindow(){

录入=new JMenuItem(\"录入学生基本信息\"); 修改=new JMenuItem(\"修改学生基本信息\"); 查询与打印=new JMenuItem(\"查询与打印学生基本信息\");

删除=new JMenuItem(\"删除学生基本信息\"); 欢迎界面=new JMenuItem(\"欢迎界面\"); bar=new JMenuBar();

fileMenu=new JMenu(\"菜单选项\"); fileMenu.add(录入); fileMenu.add(修改); fileMenu.add(查询与打印); fileMenu.add(删除); fileMenu.add(欢迎界面); bar.add(fileMenu); setJMenuBar(bar);

label=new JLabel(\"学籍管理系统\ label.setIcon(new ImageIcon(\"welcome.jpg\")); label.setFont(new Font(\"隶书\

label.setHorizontalTextPosition(SwingConstants.CENTER);

label.setForeground(Color.red); 基本信息=new HashMap(); 录入.addActionListener(this); 修改.addActionListener(this); 查询与打印.addActionListener(this); 删除.addActionListener(this); 欢迎界面.addActionListener(this); card=new CardLayout(); pCenter=new JPanel(); pCenter.setLayout(card); file=new File(\"基本信息.txt\"); if(!file.exists()){ try{

FileOutputStream out=new FileOutputStream(file);

ObjectOutputStream objectOut=new ObjectOutputStream(out);

息);

objectOut.close(); out.close(); }

catch(IOException e){} }

基本信息录入=new InputStudent(file); 基本信息修改=new ModifySituation(file); 基本信息查询与打印=new Inquest(file); 基本信息删除=new Delete(file); pCenter.add(\"欢迎界面\ pCenter.add(\"录入界面\基本信息录入); pCenter.add(\"修改界面\基本信息修改); pCenter.add(\"删除界面\基本信息删除); add(pCenter,BorderLayout.CENTER); validate(); setVisible(true);

setBounds(100,50,460,280);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ int

n=JOptionPane.showConfirmDialog(null,\"确认退出吗?\确认对话框\

JOptionPane.YES_NO_OPTION );

if(n==JOptionPane.YES_OPTION)

System.exit(0); }}); validate(); }

public void actionPerformed(ActionEvent e){

if(e.getSource()==录入){ 基本信息录入.clearMess(); card.show(pCenter,\"录入界面\"); }

else if(e.getSource()==修改){ 基本信息修改.clearMess();

11

基于数据结构的学籍管理系统

card.show(pCenter,\"修改界面\"); }

else if(e.getSource()==查询与打印){ 基本信息查询与打印.clearMess(); 基本信息查询与打

印.setLocation(getBounds().x+getBounds().width,getBounds().y); 基本信息查询与打印.setVisible(true); }

else if(e.getSource()==删除) card.show(pCenter,\"删除界面\"); else if(e.getSource()==欢迎界面) card.show(pCenter,\"欢迎界面\"); }

public static void main(String args[]){ new ManagerWindow(); } }

import java.io.*;

public class Student implements Serializable{ String

number,name,discipling,grade,borth,sex; File imagePic;

public void setNumber(String number){ this.number=number; }

public String getNumber(){ return number; }

public void setName(String name){ this.name=name; }

public String getName(){ return name; }

public void setDiscipling(String discipling){

this.discipling=discipling; }

public String getDisciping(){ return discipling; }

public void setGrade(String grade){

this.grade=grade; }

public String getGrade(){ return grade; }

public void setBorth(String borth){ this.borth=borth; }

public String getBorth(){ return borth; }

public void setSex(String sex){ this.sex=sex; }

public String getSex(){ return sex; }

public void setImagePic(File image){ imagePic=image; }

public File getImagePic(){ return imagePic; } }

import javax.swing.*; import java.io.*; import java.awt.*;

public class StudentPicture extends JPanel{ File imageFile; Toolkit tool;

public StudentPicture(){ tool=getToolkit(); }

public void setImage(File imageFile){ this.imageFile=imageFile; repaint(); }

public void paintComponent(Graphics g){ super.paintComponent(g); int w=getBounds().width; int h=getBounds().height; if(imageFile!=null){

12

Java课程设计

Image

image=tool.getImage(imageFile.getAbsolutePath());

g.drawImage(image,0,0,w,h,this); } else

g.drawString(\"没有选择照片图像\ } }

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*;

import javax.swing.filechooser.*; public class InputStudent extends JPanel implements ActionListener{ Student 学生=null; StudentPicture pic;

HashMap 基本信息表=null; JTextField 学号,姓名,年级,出生; JButton 选择照片;

JComboBox 专业; JRadioButton 男,女; ButtonGroup group=null; JButton 录入,重置;

FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File systemFile,imagePic; public InputStudent(File file){ systemFile=file;

pic=new StudentPicture(); 学号=new JTextField(5); 姓名=new JTextField(5); 专业=new JComboBox(); try{

FileReader inOne=new FileReader(\"专业.txt\");

BufferedReader inTwo= new BufferedReader(inOne); String s=null;

int i=0;

while((s=inTwo.readLine())!=null) 专业.addItem(s); inOne.close(); inTwo.close(); }

catch(IOException exp){ 专业.addItem(\"数学\");

专业.addItem(\"计算机科学与技术\"); }

年级=new JTextField(5); 出生=new JTextField(5); 选择照片=new JButton(\"选择\"); group=new ButtonGroup(); 男=new JRadioButton(\"男\ 女=new JRadioButton(\"女\ group.add(男); group.add(女);

录入=new JButton(\"录入\"); 重置=new JButton(\"重置\");

录入.addActionListener(this); 选择照片.addActionListener(this); 重置.addActionListener(this);

Box box1=Box.createHorizontalBox(); box1.add(new JLabel(\"学号:\ box1.add(学号);

Box box2=Box.createHorizontalBox(); box2.add(new JLabel(\"姓名:\ box2.add(姓名);

Box box3=Box.createHorizontalBox(); box3.add(new JLabel(\"性别:\ box3.add(男); box3.add(女);

Box box4=Box.createHorizontalBox(); box4.add(new JLabel(\"专业:\ box4.add(专业);

Box box5=Box.createHorizontalBox(); box5.add(new JLabel(\"年级:\

13

基于数据结构的学籍管理系统

box5.add(年级); box6.add(new JLabel(\"出生:\ box6.add(出生); inOne=new inTwo=new ObjectInputStream(inOne); 基本信息表 Box box6=Box.createHorizontalBox(); FileInputStream(systemFile);

Box boxH=Box.createVerticalBox(); =(HashMap)inTwo.readObject(

boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6);

boxH.add(Box.createVerticalGlue()); JPanel picPanel=new JPanel(); picPanel.setBackground(Color.green); picPanel.add(new JLabel(\"选择照片:\ picPanel.add(选择照片);

JPanel putButton=new JPanel(); putButton.add(录入);

putButton.add(重置); JPanel messPanel=new JPanel(); messPanel.add(boxH);

messPanel.setBackground(Color.cyan); putButton.setBackground(Color.red); setLayout(new BorderLayout()); JSplitPane splitV= new

JSplitPane(JSplitPane.VERTICAL_SPLIT,picPanel,pic);

JSplitPane splitH=new

JSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,splitV);

add(splitH,BorderLayout.CENTER); add(putButton,BorderLayout.SOUTH); validate(); }

public void actionPerformed(ActionEvent e){

if(e.getSource()==录入){ String number=\"\"; number=学号.getText(); if(number.length()>0){ try {

);

inOne.close(); inTwo.close(); }

catch(Exception ee){} if(基本信息

表.containsKey(number)){

String warning=\"该生基本信息已存在,请到修改页面修改!\";

JOptionPane.showMessageDialog(this,warning,\"警告\

JOptionPane.WARNING_MESSAGE); } else{

String m=\"基本信息将被录入!\"; int

ok=JOptionPane.showConfirmDialog(this,m,\"确认\

JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){ String name=姓名.getText();

String

discipling=(String)专业.getSelectedItem(); String grade=年级.getText();

String borth=出生.getText();

String sex=null; if(男.isSelected()) sex=男.getText();

else

14

Java课程设计

sex=女.getText();

学生=new Student(); 学生.setNumber(number);

学生.setName(name); 学生.setDiscipling(discipling);

学生.setGrade(grade); 学生.setBorth(borth); 学生.setSex(sex); 学生.setImagePic(imagePic);

try { outOne=new FileOutputStream(systemFile);

outTwo=new ObjectOutputStream(outOne); 基本信息表.put(number,学生); outTwo.writeObject(基本信息表);

outTwo.close(); outOne.close(); clearMess(); }

catch(Exception ee){} } } } else{

String warning=\"必须要输入学号!\";

JOptionPane.showMessageDialog(this,warning,\"警告\ } }

else if(e.getSource()==选择照片){ JFileChooser chooser=new JFileChooser();

FileNameExtensionFilter filter = new FileNameExtensionFilter(

\"JPG & GIF Images\ chooser.setFileFilter(filter);

int

state=chooser.showOpenDialog(null); File

choiceFile=chooser.getSelectedFile();

if(choiceFile!=null&&state==JFileChooser.APPROVE_OPTION){ 选择照

片.setText(choiceFile.getName()); imagePic=choiceFile; pic.setImage(imagePic); pic.repaint(); } }

else if(e.getSource()==重置){ clearMess(); } }

public void clearMess(){ 学号.setText(null); 姓名.setText(null); 年级.setText(null); 出生.setText(null); 选择照片.setText(\"选择\"); imagePic=null;

pic.setImage(imagePic); pic.repaint(); } }

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*;

public class Inquest extends JDialog implements ActionListener{ StudentPicture pic; PrintJob print; Graphics g=null;

HashMap 基本信息表; JTextField 学号,姓名,专业,年级,出生; JRadioButton 男,女;

JButton 查询,打印文本及照片,打印文本,打印照片;

15

基于数据结构的学籍管理系统

ButtonGroup group=null; FileInputStream inOne=null; ObjectInputStream inTwo=null; File systemFile=null; JPanel messPanel; Student stu;

public Inquest(File file){ setTitle(\"查询对话框\"); setModal(false); systemFile=file;

pic=new StudentPicture(); 学号=new JTextField(6); 查询=new JButton(\"查询\"); 学号.addActionListener(this); 查询.addActionListener(this); 打印文本及照片=new JButton(\"打印文本及照片\");

打印文本=new JButton(\"打印文本\"); 打印照片=new JButton(\"打印照片\"); 打印文本及照

片.addActionListener(this);

打印文本.addActionListener(this); 打印照片.addActionListener(this); 打印文本及照片.setEnabled(false); 打印文本.setEnabled(false); 打印照片.setEnabled(false); 姓名=new JTextField(5); 姓名.setEditable(false); 专业=new JTextField(5); 专业.setEditable(false); 年级=new JTextField(5); 年级.setEditable(false); 出生=new JTextField(5); 出生.setEditable(false); 男=new JRadioButton(\"男\ 女=new JRadioButton(\"女\ group=new ButtonGroup(); group.add(男); group.add(女);

Box box1=Box.createHorizontalBox(); box1.add(new JLabel(\"学号:\ box1.add(学号); box1.add(查询);

Box box2=Box.createHorizontalBox(); box2.add(new JLabel(\"姓名:\ box2.add(姓名);

Box box3=Box.createHorizontalBox(); box3.add(new JLabel(\"性别:\ box3.add(男); box3.add(女);

Box box4=Box.createHorizontalBox(); box4.add(new JLabel(\"专业:\ box4.add(专业);

Box box5=Box.createHorizontalBox(); box5.add(new JLabel(\"年级:\ box5.add(年级);

Box box6=Box.createHorizontalBox(); box6.add(new JLabel(\"出生:\ 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()); messPanel=new JPanel(); messPanel.add(boxH); JSplitPane splitH=new

JSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,pic);

add(splitH,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(打印文本及照片); pSouth.add(打印文本); pSouth.add(打印照片);

add(pSouth,BorderLayout.SOUTH); validate(); setVisible(false); setSize(360,230);

addWindowListener(new WindowAdapter(){

16

Java课程设计

public void windowClosing(WindowEvent e){

setVisible(false);

pic.setImage(stu.getImagePic()); pic.repaint(); }}); }

public void actionPerformed(ActionEvent e){

if(e.getSource()==查询||e.getSource()==学号){ String number=\"\"; number=学号.getText(); if(number.length()>0){ try {

inOne=new FileInputStream(systemFile); inTwo=new ObjectInputStream(inOne); 基本信息表

=(HashMap)inTwo.readObject();

inOne.close(); inTwo.close(); }

catch(Exception ee){} if(基本信息

表.containsKey(number)){ stu=基本信息表.get(number); 姓名.setText(stu.getName()); 专

业.setText(stu.getDisciping()); 年级.setText(stu.getGrade()); 出生.setText(stu.getBorth());

if(stu.getSex().equals(\"男\"))

男.setSelected(true); else 女.setSelected(true);

打印文本及照片.setEnabled(true); 打印文本.setEnabled(true); 打印照片.setEnabled(true); } else{

打印文本及照片.setEnabled(false); 打印文本.setEnabled(false); 打印照片.setEnabled(false);

String warning=\"该学号不存在!\";

JOptionPane.showMessageDialog(this,warning,\"警告\

JOptionPane.WARNING_MESSAGE); clearMess(); } } else{

打印文本及照片.setEnabled(false);

打印文本.setEnabled(false); 打印照片.setEnabled(false); String warning=\"必须要输入学号!\";

JOptionPane.showMessageDialog(this,warning,\"警告\

JOptionPane.WARNING_MESSAGE); } }

else if(e.getSource()==打印文本及照片){

try{

17

基于数据结构的学籍管理系统

print=getToolkit().getPrintJob(new JFrame(),\"打印\ g=print.getGraphics();

g.translate(120,200);//在打印页的坐标(120,200)开始打印文本内容 int

w=messPanel.getBounds().width; messPanel.printAll(g); g.translate(w,0); //在打印页的坐标(120+w,200)处打印照片 pic.printAll(g);

姓名.setText(stu.getName()); g.dispose(); print.end(); }

catch(Exception exp){} }

else if(e.getSource()==打印文本){ try{

print=getToolkit().getPrintJob(new JFrame(),\"打印\ g=print.getGraphics();

g.translate(120,200);//在打印页的坐标(120,200)开始打印文本内容 messPanel.printAll(g); g.dispose(); print.end(); }

catch(Exception exp){} }

else if(e.getSource()==打印照片){ try{

print=getToolkit().getPrintJob(new JFrame(),\"打印\ g=print.getGraphics(); int

w=messPanel.getBounds().width;

g.translate(120+w,200);//在打印页的坐标(120+w,200)处打印照片 pic.printAll(g); g.dispose();

print.end(); }

catch(Exception exp){} } }

public void clearMess(){ 学号.setText(null); 姓名.setText(null); 年级.setText(null); 出生.setText(null); 专业.setText(null); pic.setImage(null); pic.repaint(); } }

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*;

import javax.swing.filechooser.*;

public class ModifySituation extends JPanel implements ActionListener{ StudentPicture pic;

HashMap 基本信息表=null; JTextField 学号,姓名,年级,出生; JComboBox 专业;

JButton 选择照片; JRadioButton 男,女; ButtonGroup group=null; JButton 开始修改,录入修改,重置; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File systemFile,imagePic; JComboBox oldMess; Student stu=null;

public ModifySituation(File file){ systemFile=file;

pic=new StudentPicture(); 学号=new JTextField(6);

姓名=new JTextField(6);

18

Java课程设计

专业=new JComboBox(); try{

FileReader inOne=new FileReader(\"专业.txt\");

BufferedReader inTwo= new BufferedReader(inOne); String s=null; int i=0;

while((s=inTwo.readLine())!=null) 专业.addItem(s); inOne.close(); inTwo.close(); }

catch(IOException exp){ 专业.addItem(\"数学\");

专业.addItem(\"计算机科学与技术\"); }

年级=new JTextField(6); 出生=new JTextField(6); 选择照片=new JButton(\"选择\"); group=new ButtonGroup(); 男=new JRadioButton(\"男\ 女=new JRadioButton(\"女\ group.add(男); group.add(女);

oldMess=new JComboBox();

开始修改=new JButton(\"开始修改\"); 录入修改=new JButton(\"录入修改\"); 录入修改.setEnabled(false); 选择照片.setEnabled(false); 重置=new JButton(\"重置\"); 学号.addActionListener(this); 开始修改.addActionListener(this); 录入修改.addActionListener(this); 重置.addActionListener(this); 选择照片.addActionListener(this); box1.add(new JLabel(\"输入要修改信息的学号:\ box1.add(学号); box1.add(开始修改);

box2.add(new JLabel(\"(新)姓名:\ box2.add(姓名);

Box box3=Box.createHorizontalBox(); box3.add(new JLabel(\"(新)性别:\ box3.add(男); box3.add(女);

Box box4=Box.createHorizontalBox(); box4.add(new JLabel(\"(新)专业:\ box4.add(专业);

Box box5=Box.createHorizontalBox(); box5.add(new JLabel(\"(新)年级:\ box5.add(年级);

Box box6=Box.createHorizontalBox(); box6.add(new JLabel(\"(新)出生:\ box6.add(出生);

Box box7=Box.createHorizontalBox(); box7.add(new JLabel(\"学生已有的数据:\ box7.add(oldMess);

Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(box7);

boxH.add(Box.createVerticalGlue()); JPanel picPanel=new JPanel();

picPanel.setBackground(Color.green); picPanel.add(new JLabel(\"选择照片:\

JPanel putButton=new JPanel();

putButton.setBackground(Color.yellow); putButton.add(录入修改); JPanel messPanel=new JPanel();

Box box1=Box.createHorizontalBox(); picPanel.add(选择照片);

Box box2=Box.createHorizontalBox(); putButton.add(重置);

19

基于数据结构的学籍管理系统

messPanel.setBackground(Color.pink); messPanel.add(boxH);

setLayout(new BorderLayout()); JSplitPane splitV= new

JSplitPane(JSplitPane.VERTICAL_SPLIT,picPanel,pic);

JSplitPane splitH=new

JSplitPane(JSplitPane.HORIZONTAL_SPLIT,mess oldMess.addItem(\"专业:\"+stu.getDisciping());

oldMess.addItem(\"年级:\"+stu.getGrade());

oldMess.addItem(\"出生日期:\"+stu.getBorth());

if(stu.getSex().equals(\"男\"))

男.setSelected(true); Panel,splitV);

add(splitH,BorderLayout.CENTER); add(putButton,BorderLayout.SOUTH); validate(); }

public void actionPerformed(ActionEvent e){

if(e.getSource()==开始修改||e.getSource()==学号){

oldMess.removeAllItems(); String number=\"\"; imagePic=null; stu=null;

number=学号.getText(); if(number.length()>0){ try {

inOne=new FileInputStream(systemFile); inTwo=new ObjectInputStream(inOne); 基本信息表

=(HashMap)inTwo.readObject();

inOne.close(); inTwo.close(); }

catch(Exception ee){} if(基本信息

表.containsKey(number)){ 录入修改.setEnabled(true); 选择照片.setEnabled(true); stu=基本信息表.get(number); oldMess.addItem(\"姓名:\"+stu.getName());

else

女.setSelected(true); imagePic=stu.getImagePic(); pic.setImage(imagePic); pic.repaint();

姓名.setText(stu.getName()); 年

级.setText(stu.getGrade()); 出

生.setText(stu.getBorth()); } else{

录入修改.setEnabled(false); 选择照片.setEnabled(false); String warning=\"该学号不存在!\";

JOptionPane.showMessageDialog(this,warning,\"警告\

JOptionPane.WARNING_MESSAGE); clearMess(); } } else{

录入修改.setEnabled(false); 选择照片.setEnabled(false); String warning=\"必须要输入学号!\";

JOptionPane.showMessageDialog(this,warning,\"警告\ clearMess(); } }

else if(e.getSource()==录入修改){

20

Java课程设计

String number=\"\"; number=学号.getText(); if(number.length()>0){ try {

inOne=new FileInputStream(systemFile); inTwo=new ObjectInputStream(inOne); 基本信息表

=(HashMap)inTwo.readObject();

inOne.close(); inTwo.close(); }

catch(Exception ee){} if(基本信息

表.containsKey(number)){

String question=\"该生基本信息已存在,您想修改他(她)的基本信息吗?\";

JOptionPane.showMessageDialog(this,question,\"警告\

JOptionPane.QUESTION_MESSAGE);

String m=\"基本信息将被修改!\";

int

ok=JOptionPane.showConfirmDialog(this,m,\"确认\

JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){ String name=姓名.getText();

if(name.length()==0) name=stu.getName();

String

discipling=(String)专业.getSelectedItem(); if(discipling==null)

discipling=stu.getDisciping();

String grade=年级.getText();

if(grade.length()==0) grade=stu.getGrade();

String borth=出生.getText();

if(borth.length()==0) borth=stu.getBorth();

String sex=null; if(男.isSelected()) sex=男.getText(); else

sex=女.getText(); if(imagePic==null) imagePic=stu.getImagePic();

Student 学生=new Student();

学生.setNumber(number); 学生.setName(name);

学生.setDiscipling(discipling);

学生.setGrade(grade); 学生.setBorth(borth); 学生.setSex(sex); 学生.setImagePic(imagePic); try{

outOne=new FileOutputStream(systemFile); outTwo=new ObjectOutputStream(outOne); 基本信息表.put(number,学生); outTwo.writeObject(基本信息表);

outTwo.close(); outOne.close(); clearMess(); }

21

基于数据结构的学籍管理系统

catch(Exception ee){} 录入修改.setEnabled(false); 选择照片.setEnabled(false); } else

if(ok==JOptionPane.NO_OPTION){ 录入修改.setEnabled(true); 选择照片.setEnabled(true); } } else{

String warning=\"该学号没有基本信息,不能修改!\";

JOptionPane.showMessageDialog(this,warning,\"警告\

JOptionPane.WARNING_MESSAGE);

录入修改.setEnabled(false); 选择照片.setEnabled(false); clearMess(); } } else{

String warning=\"必须要输入学号!\";

JOptionPane.showMessageDialog(this,warning,\"警告\ 录入修改.setEnabled(false); clearMess();

录入修改.setEnabled(false); 选择照片.setEnabled(false); } }

else if(e.getSource()==选择照片){ JFileChooser chooser=new JFileChooser();

FileNameExtensionFilter filter = new FileNameExtensionFilter(

\"JPG & GIF Images\ chooser.setFileFilter(filter); int

state=chooser.showOpenDialog(null); File

choiceFile=chooser.getSelectedFile();

if(choiceFile!=null&&state==JFileChooser.APPROVE_OPTION){ 选择照

片.setText(choiceFile.getName()); imagePic=choiceFile; pic.setImage(imagePic); pic.repaint(); } }

else if(e.getSource()==重置){ clearMess();

录入修改.setEnabled(false); 选择照片.setEnabled(false); } }

public void clearMess(){ 学号.setText(null); 姓名.setText(null); 年级.setText(null); 出生.setText(null);

oldMess.removeAllItems(); 选择照片.setText(\"选择\"); imagePic=null;

pic.setImage(imagePic); pic.repaint(); } }

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*;

public class Delete extends JPanel implements ActionListener{

HashMap 基本信息表=null;

JTextField 学号,姓名,专业,年级,出生;

22

Java课程设计

JRadioButton 男,女; JButton 删除;

ButtonGroup group=null; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; box4.add(new JLabel(\"专业:\ box4.add(专业);

Box box5=Box.createHorizontalBox(); box5.add(new JLabel(\"年级:\ box5.add(年级); File systemFile=null; Box box6=Box.createHorizontalBox();

public Delete(File file){ systemFile=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); 出生=new JTextField(10); 出生.setEditable(false);

男=new JRadioButton(\"男\ 女=new JRadioButton(\"女\ group=new ButtonGroup(); group.add(男); group.add(女);

Box box1=Box.createHorizontalBox(); box1.add(new JLabel(\"输入要删除的学号:\ box1.add(学号); box1.add(删除); Box box2=Box.createHorizontalBox(); box2.add(new JLabel(\"姓名:\ box2.add(姓名); Box box3=Box.createHorizontalBox(); box3.add(new JLabel(\"性别:\ box3.add(男); box3.add(女);

Box box4=Box.createHorizontalBox(); box6.add(new JLabel(\"出生:\ 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);

validate(); }

public void actionPerformed(ActionEvent e){

if(e.getSource()==删除

||e.getSource()==学号){ String number=\"\"; number=学号.getText(); if(number.length()>0){ try {

inOne=new FileInputStream(systemFile); inTwo=new ObjectInputStream(inOne);

基本信息表=(HashMap)inTwo.readObject(); inOne.close(); inTwo.close(); }

catch(Exception ee){}

23

基于数据结构的学籍管理系统

if(基本信息

表.containsKey(number)){

Student stu=(Student)基本信 年级.setText(null);

出息表.get(number); 姓名.setText(stu.getName()); 专

业.setText(stu.getDisciping()); 年

级.setText(stu.getGrade()); 出

生.setText(stu.getBorth());

if(stu.getSex().equals(\"男\"))

男.setSelected(true); else

女.setSelected(true); String m=\"确定要删除该学号及全部信息吗?\"; int

ok=JOptionPane.showConfirmDialog(this,m,\"确认\

JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){ 基本信息表.remove(number); try{

outOne=new FileOutputStream(systemFile); outTwo=new ObjectOutputStream(outOne); outTwo.writeObject(基本信息表);

outTwo.close(); outOne.close(); 学号.setText(null);

名.setText(null); 专业.setText(null);

生.setText(null); }

catch(Exception ee){} } else

if(ok==JOptionPane.NO_OPTION){

学号.setText(null); 姓名.setText(null); 专业.setText(null); 年级.setText(null); 出生.setText(null); } } else{

String warning=\"该学号不存在!\";

JOptionPane.showMessageDialog(this,warning,\"警告\

JOptionPane.WARNING_MESSAGE); 学号.setText(null); } } else{

String warning=\"必须要输入学号!\";

JOptionPane.showMessageDialog(this,warning,\"警告\

JOptionPane.WARNING_MESSAGE); } } } }

24

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务