JAVA课程设计-学生信息管理系统(个人博客)

1. 团队课程设计博客链接

http://www.cnblogs.com/Min21/p/7064093.html

2.个人负责模块或任务说明

负责person类的编写,建立person对象,
完成Menu中增删改查的功能。

3.自己的代码提交记录截图

JAVA课程设计-学生信息管理系统(个人博客)

4..自己负责模块或任务详细说明

1、建立对象建立可序列化对象person,并构建函数。

主要代码:
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.增加学生信息功能
but1.addActionListener(new ActionListener() { // 增加,内部类//进行某项操作时触发功能
public void actionPerformed(ActionEvent e) {//用于接收操作事件的侦听器接口
if (e.getSource() == but1) {
but3.setEnabled(false);//使but3这个按钮变灰不可点击了
String number1 = number.getText();
if (number1.length() == 12) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));//读回对象
has = (Hashtable) in.readObject(); in.close();
} catch (Exception e1) {
}
} else {
JOptionPane.showMessageDialog(null, "请输入12位数字的学号");//提示框显示
}
//
if (number1.length() == 12) {
if (has.containsKey(number1)) { JOptionPane.showMessageDialog(null, "该生信息已存在,请到修改页面修改!");
} else {
String name1 = name.getText();
String dor1 = dor.getText();
String address1 = address.getText();
String sex1 = sex.getText();
String date1 = date.getText();
String pol1 = pol.getText();
String phone1 = phone.getText();
Person per = null;
per = new Person(number1, name1, dor1, address1, sex1, date1, pol1, phone1);
has.put(number1, per);// ???
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(has);
out.close();
JOptionPane.showMessageDialog(null, "添加成功!");
} catch (Exception e1) {}
}
}
}
} 3.)修改功能:为了防止误修改,首先要查看,才能修改,查看后直接改输入栏中的数据,点击修改,既修改成功。
but3.addActionListener(new ActionListener() { // 修改
public void actionPerformed(ActionEvent e) { if (e.getSource() == but3) {
but3.setEnabled(false);
String number1 = number.getText();
String name1 = name.getText();
String dor1 = dor.getText();
String address1 = address.getText();
String sex1 = sex.getText();
String date1 = date.getText();
String pol1 = pol.getText();
String phone1 = phone.getText();
Person per = new Person(number1, name1, dor1, address1, sex1, date1, pol1, phone1);
has.put(number1, per);
JOptionPane.showMessageDialog(null, "修改成功");
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(has);
out.close();
} catch (Exception e1) {
}
}
}
}); 4.查看功能:首先输入要查看的学号,点查看,信息将会显示在输入栏中。如果学号不存在,下面会有提示。
but4.addActionListener(new ActionListener() { // 查看
public void actionPerformed(ActionEvent e) { if (e.getSource() == but4) {
but3.setEnabled(false);
String number1 = number.getText();
if (number1.length() == 12) {
if (has.containsKey(number1)) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
has = (Hashtable) in.readObject();
in.close();
} catch (Exception e1) {
}
Person per = (Person) has.get(number1);
name.setText(per.getName());
dor.setText(per.getDor());
address.setText(per.getAddress());
sex.setText(per.getSex());
date.setText(per.getDate());
pol.setText(per.getPol());
phone.setText(per.getPhone()); but3.setEnabled(true);
} else {
JOptionPane.showMessageDialog(null, "学号不存在");
}
} else {
JOptionPane.showMessageDialog(null, "请输入12位数字的学号");
}
}
} });
5.(5)删除功能:先输入要删除的学号,点删除,该学生的信息将被移除,在查看该学号,将不存在。
but2.addActionListener(new ActionListener() { // 删除
public void actionPerformed(ActionEvent e) {
if (e.getSource() == but2) {
but3.setEnabled(false);
String number1 = number.getText();
if (number1.length() == 12) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
has = (Hashtable) in.readObject();
in.close();
} catch (Exception e1) {
}
} else {
JOptionPane.showMessageDialog(null, "请输入12位数字的学号");
}
if (has.containsKey(number1)) {
has.remove(number1);
ObjectOutputStream out = null;
JOptionPane.showMessageDialog(null, "删除成功");
try {
out = new ObjectOutputStream(new FileOutputStream(file));
//out.writeObject(has);
out.close();
} catch (IOException ex) {
Logger.getLogger(Menu.class.getName()).log(Level.SEVERE, null, ex);//记录当前类可能发生的异常
}
} else {
JOptionPane.showMessageDialog(null, "学号不存在");
}
}
}
});

5.五.课程设计感想

我们打算做文本io时想实现内存与文本的交互一直无法成功,后来百度查了一下是需要将数据可序列化才能行,而且还要用ObjectOutputStream和ObjectInputStream来传递数据,而它们对象序列话是在它们中实现的,这些我们都没学过。还好书上有,网上也有它们的解析,于是我们就一点一点的尝试,最终实现内存与文本的交互并把数据存到文本里。
上一篇:java操作数据库,以页面显示学生信息为例


下一篇:node.js(小案例)_实现学生信息增删改