一.功能调查与系统功能框架图

二.类的设计
定义一个学生管理类,内有增、删、改、查4个方法。

在main函数中,实例化学生管理类,并根据菜单的选项分别调用4个方法。
三.类说明
1.建立对象
import java.io.Serializable;
public class Person implements Serializable{
private String num;
private String name;
private String dor;
private String address;
private String sex;
private String date;
private String pol;
private String phone;
public Person(){}
public Person(String num,String name,String dor,String address,String sex,String date,String pol,String phone ){
this.num=num;
this.name=name;
this.dor=dor;
this.address=address;
this.sex=sex;
this.date=date;
this.pol=pol;
this.phone=phone;
}
public void setNum(String num){
this.num=num;
}
public String getNum(){
return num;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setDor(String dor){
this.dor=dor;
}
public String getDor(){
return dor;
}
public void setAddress(String address){
this.address=address;
}
public String getAddress(){
return address;
}
public void setSex(String sex){
this.sex=sex;
}
public String getSex(){
return sex;
}
public void setDate(String date){
this.date=date;
}
public String getDate(){
return date;
}
public void setPol(String pol){
this.pol=pol;
}
public String getPol(){
return pol;
}
public void setPhone(String phone){
this.phone=phone;
}
public String getPhone(){
return phone;
}

}
2.登入界面
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.
;

class LoginCheck{
private String name;
private String password;
public LoginCheck(String name,String password){
this.name=name;
this.password=password;
}
public boolean equals(){
if("admin".equals(name)&&"admin".equals(password)){
return true;
}else{
return false;
}
}
};
class ActionHandle{
private JFrame frame=new JFrame("信息管理系统");
private JTextField name=new JTextField();//设置文本框
private JPasswordField pass=new JPasswordField();
private JLabel but1=new JLabel("用户名:");
private JLabel but2=new JLabel("密 码:");
private JButton but3=new JButton("登陆");
private JButton but4=new JButton("重置");

public ActionHandle(){
	but3.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			if(e.getSource()==but3){
				String sname=name.getText();
				String spass=new String(pass.getPassword());
				LoginCheck log=new LoginCheck(sname,spass);
				if(log.equals()){
					try {
						new Menu();
					} catch (Exception e1) {
						
						e1.printStackTrace();
					}
					frame.setVisible(false);
					
				}else{
					JOptionPane.showMessageDialog(null, "登录失败,错误的用户名或密码!");
				}
			}
		}					
	});		
	but4.addActionListener(

new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==but4){
name.setText("");
pass.setText("");
}
}

	});
	frame.setLayout(null);
	but1.setBounds(80, 40 , 80,30);
	name.setBounds(140,40, 120, 30);	//
	but2.setBounds(80, 80 , 80,30);
	pass.setBounds(140,80, 120, 30);
	but3.setBounds(100, 150 , 60,30);
	but4.setBounds(180, 150 , 60,30);
	frame.setSize(400,330);		
	frame.setLocation(300, 200);
	frame.add(but1);
	frame.add(name);
	frame.add(pass);
	frame.add(but2);
	frame.add(but3);
	frame.add(but4);
	frame.setVisible(true);
}

}
public class Enter{
public static void main(String[] args) {

	new ActionHandle();
}

}
3.管理界面
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.swing.
;

public class Menu {
private JButton but1 = new JButton("增加数据"); // 按钮
private JButton but2 = new JButton("删除数据");
private JButton but3 = new JButton("修改数据");
private JButton but4 = new JButton("查看数据");
private JButton but0 = new JButton("系统退出");
private JButton but5 = new JButton("显示");
private JButton clear = new JButton("清空");

private JTextField number = new JTextField();// 文本框
private JTextField name = new JTextField();
private JTextField dor = new JTextField();
private JTextField address = new JTextField();
private JTextField sex = new JTextField();
private JTextField date = new JTextField();
private JTextField pol = new JTextField();
private JTextField phone = new JTextField();

private JTextArea show = new JTextArea(16, 30);// 文本区

private JLabel lab1 = new JLabel("姓名:");//标签
private JLabel lab2 = new JLabel("宿舍号:");
private JLabel num = new JLabel("学号:");
private JLabel lab4 = new JLabel("家庭住址:");
private JLabel lab5 = new JLabel("性别:");
private JLabel lab6 = new JLabel("出生日期:");
private JLabel lab7 = new JLabel("政治面貌:");
private JLabel lab8 = new JLabel("电话:");

private JFrame frame = new JFrame("信息管理系统"); // 框架
private JFrame frame1 = new JFrame("显示信息");

Hashtable<String, Person> has = new Hashtable<String, Person>();// 哈希表,加密,文件乱码
File file = new File("学生信息.txt");// 新建一个文件

public Menu() {
	if (!file.exists()) {
		try {
			ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));//把一个实例的对象以文件的形式保存到磁盘上
			out.writeObject(has);
			out.close();
		} catch (IOException e) {
		}
	}	

4.显示
but5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == but5) {
frame1.setVisible(true);
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
has = (Hashtable) in.readObject();
in.close();
} catch (Exception ee) {
}
if (has.isEmpty()) {
show.append("目前还没有学生的信息记录!\n");
} else {

					for (Enumeration enu = has.elements(); enu.hasMoreElements();) {
						Person per = (Person) enu.nextElement();

String str = " <学号>:" + per.getNum() + "\n" + " <姓名>:" + per.getName() + "\n" + " <宿舍号>:"
+ per.getDor() + "\n" + " <家庭住址>:" + per.getAddress() + "\n" + " <性别>:"
+ per.getSex() + "\n" + "<出生日期>:" + per.getDate() + "\n" + " <政治面貌>:"
+ per.getPol() + "\n" + " <电话>:" + per.getPhone() + "\n" + "\n";
show.append(str);
}
String str2 = "------------------------------结束---------------------------------------------------"
+ "\n";
show.append(str2);
}
}
}

	});

5.清空
clear.addActionListener(new ActionListener() { // 清空
public void actionPerformed(ActionEvent e) {
if (e.getSource() == clear) {

				number.setText(null);
				dor.setText(null);
				name.setText(null);
				address.setText(null);
				sex.setText(null);
				date.setText(null);
				pol.setText(null);
				phone.setText(null);
			}
		}
	});

5.功能演示
5.1 界面

密码输入错误时

输入正确登入

5.2 添加信息

按显示后

5.3查询信息
输入学号 学号必须为12位


按下查询 由于刚刚删除了数据 所以数据不存在

5.4 修改信息
按查询后显示信息 修改宿舍信息为722

按显示后

5.5 删除信息
按查询后点击删除信息 学号必须为12位

按显示后

6.git
https://gitee.com/YuetCcang/JAVA095/tree/master