Java学籍管理系统

1、InformationWindow.java
	该文件完成系统的启动,显示主界面。
1 import java.awt.*;
2 import java.awt.event.*;
3 import javax.swing.*;
4 import java.io.*;
5 import java.util.HashMap;
6 /**
7  * 启动系统,完成主界面的初始化
8  */
9 public class InformationWindow extends JFrame implements ActionListener {
10 	private InputStudentInformation inputStudentInformation; // 录入信息
11 	private ModifyStudentInformation modifyStudentInformation; // 修改信息
12 	private QueryStudentInformation queryStudentInformation; // 查询信息
13 	private DeleteStudentInformation deleteStudentInformation; // 删除信息
private ExportStudentInformation exportStudentInformation; // 导出信息

14 	private JMenuBar bar;// 菜单栏
15 	private JMenu fileMenu;
16 	private JMenuItem inputItem, modifyItem, queryItem, deleteItem, exportItem
17 			welcomeItem;// 各菜单项
18 	private HashMap<String, Student> informationTable = null; // 学生信息表
19 	private File file = null;
20 	private CardLayout card = null;
21 	private JLabel label = null;
22 	private JPanel pCenter;
23 	/**
24 	 * 构造方法,初始化主界面
25 	 */
26 	public InformationWindow() {	
27 		informationTable = new HashMap<String,Student>();
28 		initFrame();
29 		setVisible(true);
30 		setBounds(100, 50, 380, 350);
31 		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
32 		addWindowListener(new WindowAdapter() {
33 			public void windowClosing(WindowEvent e) {
34 				int n = JOptionPane.showConfirmDialog(null, "确认退出吗?", "确认对话框",
35 						JOptionPane.YES_NO_OPTION);
36 				if (n == JOptionPane.YES_OPTION)
37 					System.exit(0);
38 			}
39 		});
40 		setResizable(false);
41 		validate();
42 	}
43 	/**
44 	 * 初始化主界面的各个组件
45 	 */
46 	public void initFrame() {
47 		inputItem = new JMenuItem("录入");
48 		modifyItem = new JMenuItem("修改");
49 		queryItem = new JMenuItem("查询");
50 		deleteItem = new JMenuItem("删除");
exportItem = new JMenuItem("导出");

51 		welcomeItem = new JMenuItem("欢迎界面");
52 		bar = new JMenuBar();
53 		fileMenu = new JMenu("菜单选项");
54 		fileMenu.add(inputItem);
55 		fileMenu.add(modifyItem);
56 		fileMenu.add(queryItem);
57 		fileMenu.add(deleteItem);
fileMenu.add(exportItem);
58 		fileMenu.add(welcomeItem);
59 		bar.add(fileMenu);
60 		setJMenuBar(bar);
61 		label = new JLabel("学籍管理系统", JLabel.CENTER);
62 		label.setIcon(new ImageIcon("welcome.jpg"));
63 		label.setFont(new Font("隶书", Font.BOLD, 36));
64 		label.setHorizontalTextPosition(SwingConstants.CENTER);
65 		label.setForeground(Color.red);
66 		informationTable = new HashMap<String, Student>();
67 		inputItem.addActionListener(this);
68 		modifyItem.addActionListener(this);
69 		queryItem.addActionListener(this);
70 		deleteItem.addActionListener(this);
exportItem.addActionListener(this);
71 		welcomeItem.addActionListener(this);
72 		card = new CardLayout();
73 		pCenter = new JPanel();
74 		pCenter.setLayout(card);
75 		file = new File("基本信息.txt");
76 		if (!file.exists()) {
77 			try {
78 				FileOutputStream out = new FileOutputStream(file);
79 				ObjectOutputStream objectOut = new ObjectOutputStream(out);
80 				objectOut.writeObject(informationTable);
81 				objectOut.close();
82 				out.close();
83 			} catch (IOException e) {
84 			}
85 		}
86 		inputStudentInformation = new InputStudentInformation(file);
87 		modifyStudentInformation = new ModifyStudentInformation(file);
88 		queryStudentInformation = new QueryStudentInformation(file);
89 		deleteStudentInformation = new DeleteStudentInformation(file);
exportStudentInformation = new ExportStudentInformation(file);
90 		pCenter.add("欢迎界面", label);
91 		pCenter.add("录入界面", inputStudentInformation);
92 		pCenter.add("删除界面", deleteStudentInformation);
93 		pCenter.add("查询界面", queryStudentInformation);
94 		pCenter.add("修改界面", modifyStudentInformation);
pCenter.add("导出界面", exportStudentInformation);
95 		add(pCenter, BorderLayout.CENTER);
96 	}
97 	/**
98 	 * 当点击录入、修改、查询、删除、欢迎菜单项时执行的操作
99 	 */
100 	public void actionPerformed(ActionEvent e) {
101 		if (e.getSource() == inputItem) {
102 			inputStudentInformation.clearMessage();
103 			card.show(pCenter, "录入界面");
104 		} else if (e.getSource() == modifyItem) {
105 			modifyStudentInformation.clearMessage();
106 			card.show(pCenter, "修改界面");
107 		} else if (e.getSource() == queryItem) {
108 			queryStudentInformation.clearMessage();
109 			card.show(pCenter, "查询界面");
110 		} else if (e.getSource() == exportItem) {
105 			exportStudentInformation.clearMessage();
106 			card.show(pCenter, "导出界面");
107 		} else if (e.getSource() == deleteItem)
111 			card.show(pCenter, "删除界面");
112 		else if (e.getSource() == welcomeItem)
113 			card.show(pCenter, "欢迎界面");
114 	}
115 	/**
116 	 * 启动系统
117 	 */
118 	public static void main(String args[]) {
119 		new InformationWindow();
120 	}
121 }
2、Student.java
	该文件主要定义学生基本信息,实现对象的序列化。
1 import java.io.File;
2 import java.io.Serializable;
3 /**
4  * Student类,实现Serializable接口
5  */
6 public class Student implements Serializable{
7 	private File imagePic;
8 	private String number,name,sex,major,grade,birthday,graduated;
9     public void setNumber(String number){
10        this.number=number;
11     }
12     public String getNumber(){
13        return number;
14     }
15     public void setName(String name){
16        this.name=name;
17     }
18     public String getName(){
19        return name;
20     }
21     public void setGrade(String grade){
22        this.grade=grade;
23     }
24     public String getGrade(){
25        return grade;
26     }
27     public void setSex(String sex){
28        this.sex=sex;
29     }
30     public String getSex(){
31        return sex;
32     }
33     public void setImagePic(File image){
34         imagePic=image;
35     }
36     public File getImagePic(){
37         return imagePic;
38     }
39 	public String getMajor() {
40 		return major;
41 	}
42 	public void setMajor(String major) {
43 		this.major = major;
44 	}
45 	public String getBirthday() {
46 		return birthday;
47 	}
48 	public void setBirthday(String birthday) {
49 		this.birthday = birthday;
50 	} 
public void setGraduated(String graduated){
        this.graduated= graduated;
    }
    public String getGraduated(){
       return graduated;
     }

51 }
3、StudentPicture.java
该文件完成显示学生照片的功能。
1 import javax.swing.*;
2 import java.io.*;
3 import java.awt.*;
4 /**
5  * 显示学生照片
6  */
7 public class StudentPicture extends JPanel {
8 	private File imageFile;// 存放图像文件的引用
9 	private Toolkit tool;// 负责创建Image对象
10 	/**
11 	 * 构造方法,初始化对象
12 	 */
13 	public StudentPicture() {
14 		tool = getToolkit();
15 		setBorder(BorderFactory.createLineBorder(Color.black));
16 		setBorder(BorderFactory.createLoweredBevelBorder());
17 	}
18 	/**
19 	 * 设置imageFile对象
20 	 */
21 	public void setImage(File imageFile) {
22 		this.imageFile = imageFile;
23 		repaint();
24 	}
25 	/**
26 	 * 显示照片
27 	 */
28 	public void paintComponent(Graphics g) {
29 		super.paintComponent(g);
30 		int w = getBounds().width;
31 		int h = getBounds().height;
32 		if (imageFile != null) {
33 			// 获得图像
34 			Image image = tool.getImage(imageFile.getAbsolutePath()); 
35 			g.drawImage(image, 0, 0, w, h, this);// 绘制图像
36 		} else
37 			g.drawString("没有选择照片图像!", 20, 30);
38 	}
39 }
4、InputStudentInformation.java
该文件完成录入学生基本信息的功能。
1 import java.awt.*;
2 import java.awt.event.*;
3 import javax.swing.*;
4 import java.io.*;
5 import java.util.*;
6 import javax.swing.filechooser.*;
7 /**
8  * 录入学生信息类,负责提供录入学生信息的界面
9  */
10 public class InputStudentInformation extends JPanel implements ActionListener {
11 	private Student student = null;// 学生对象
12 	private StudentPicture studentPicture;// 学生图像
13 	private HashMap<String, Student> informationTable;
14 	private JTextField numberTField, nameTField, gradeTField, birthdayTField,graduatedTField;
15 	private JButton picButton;// 选择照片按钮
16 	private JLabel promptLabel;//提示信息
17 	private JComboBox<String> majorComBox; // 专业列表框
18 	private JRadioButton maleRButton, femaleRButton;// 单选按钮,选择男或者女
19 	private ButtonGroup buttonGroup = null;
20 	private JButton inputButton, resetButton;// 输入按钮、重置按钮
21 	private FileInputStream fileInputStream = null;// 文件输入流对象
22 	private ObjectInputStream objectInputStream = null;// 对象输入流对象
23 	private FileOutputStream fileOutputStream = null;// 文件输出流对象
24 	private ObjectOutputStream objectOutputStream = null;// 对象输出流对象
25 	private File systemFile, imagePic;
26 	private JPanel putButtonPanel;//录入和重置按钮的容器
27 	private JPanel messPanel,picPanel;//基本信息和照片的容器
28 	/**
29 	 *构造方法,初始化录入界面
30 	 */
31 	public InputStudentInformation(File file) {
32 		systemFile = file;
33 		studentPicture = new StudentPicture();	
34 		informationTable = new HashMap<String,Student>();
35 		promptLabel = new JLabel("请输入以下信息:",JLabel.LEFT);
36 		promptLabel.setFont(new Font("宋体",Font.BOLD,13));//设置提示信息的字体
37 		promptLabel.setForeground(Color.RED);
38 		promptLabel.setOpaque(true);//设置为不透明
39 		promptLabel.setBackground(new Color(216,224,231));//设置背景颜色	
40 		initMessPanel();
41 		initPutButtonJPanel();
42 		initPicPanel();
43 		setLayout(new BorderLayout());
44 		JSplitPane splitH = new JSplitPane(JSplitPane.HORIZONTA
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值