;
con.validate();
setVisible(false);
setBounds(100,200,360,270);
addWindowListener(newWindowAdapter()
{publicvoidwindowClosing(WindowEvente)
{
setVisible(false);
}
});
}
publicvoidactionPerformed(ActionEvente)
{
姓名.setText(null);
所学专业.setText(null);
家庭住址.setText(null);
出生.setText(null);
if(e.getSource()==查询||e.getSource()==学号)
{
Stringnumber="";
number=学号.getText();
if(number.length()>0)
{
try{
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
基本信息表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exceptionee)
{
}
if(基本信息表.containsKey(number))
{
Studentstu=(Student)基本信息表.get(number);
姓名.setText(stu.getName());
所学专业.setText(stu.getDisciping());
家庭住址.setText(stu.getGrade());
出生.setText(stu.getBorth());
if(stu.getSex().equals("男"))
{
男.setSelected(true);
}
else
{
女.setSelected(true);
}
}
else
{
Stringwarning="该学号不存在!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
}
else
{
Stringwarning="必须要输入学号!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
}
}
}
3.修改界面
1).成员变量
主要成员变量
描述
变量类型
变量名称
存放"学生"对象的散列表
输入学生基本信息的文本条
Hashtabel
JTextField
基本信息表
学号,姓名,所学专业,家庭住址,出生
2).方法
主要方法
名称
功能
备注
ModifySituation
actionPerform
创建学生信息修改界面
处理ActionEvent事件
构造方法
接口方法
3).代码
ModifySituation.java
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjava.io.*;
importjava.util.*;
publicclassModifySituationextendsJPanelimplementsActionListener
{
Hashtable基本信息表=null;
JTextField学号,姓名,所学专业,家庭住址,出生;
JRadioButton男,女;
ButtonGroupgroup=null;
JButton开始修改,录入修改,重置;
FileInputStreaminOne=null;
ObjectInputStreaminTwo=null;
FileOutputStreamoutOne=null;
ObjectOutputStreamoutTwo=null;
Filefile=null;
publicModifySituation(Filefile)
{
this.file=file;
学号=newJTextField(10);
姓名=newJTextField(10);
所学专业=newJTextField(10);
家庭住址=newJTextField(10);
出生=newJTextField(10);
group=newButtonGroup();
男=newJRadioButton("男",true);
女=newJRadioButton("女",false);
group.add(男);
group.add(女);
开始修改=newJButton("开始修改");
录入修改=newJButton("录入修改");
录入修改.setEnabled(false);
重置=newJButton("重置");
学号.addActionListener(this);
开始修改.addActionListener(this);
录入修改.addActionListener(this);
重置.addActionListener(this);
Boxbox1=Box.createHorizontalBox();
box1.add(newJLabel("输入要修改信息的TER));
box1.add(学号);
box1.add(开始修改);
Boxbox2=Box.createHorizontalBox();
box2.add(newJLabel("(新)姓名:",JLabel.CENTER));
box2.add(姓名);
Boxbox3=Box.createHorizontalBox();
box3.add(newJLabel("(新)性别:",JLabel.CENTER));
box3.add(男);
box3.add(女);
Boxbox4=Box.createHorizontalBox();
box4.add(newJLabel("(新)所学专业:",JLabel.CENTER));
box4.add(所学专业);
Boxbox5=Box.createHorizontalBox();
box5.add(newJLabel("(新)家庭住址:",JLabel.CENTER));
box5.add(家庭住址);
Boxbox6=Box.createHorizontalBox();
box6.add(newJLabel("(新)出生:",JLabel.CENTER));
box6.add(出生);
BoxboxH=Box.createVerticalBox();
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(box5);
boxH.add(box6);
boxH.add(Box.createVerticalGlue());
JPanelpCenter=newJPanel();
pCenter.add(boxH);
setLayout(newBorderLayout());
add(pCenter,BorderLayout.CENTER);
JPanelpSouth=newJPanel();
pSouth.add(录入修改);
pSouth.add(重置);
add(pSouth,BorderLayout.SOUTH);
validate();
}
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==开始修改||e.getSource()==学号)
{
Stringnumber="";
number=学号.getText();
if(number.length()>0)
{
try{
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
基本信息表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exceptionee)
{
}
if(基本信息表.containsKey(number))
{
录入修改.setEnabled(true);
Studentstu=(Student)基本信息表.get(number);
姓名.setText(stu.getName());
所学专业.setText(stu.getDisciping());
家庭住址.setText(stu.getGrade());
出生.setText(stu.getBorth());
if(stu.getSex().equals("男"))
{
男.setSelected(true);
}
else
{
女.setSelected(true);
}
}
else
{
录入修改.setEnabled(false);
Stringwarning="该学号不存在!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
学号.setText(null);
姓名.setText(null);
所学专业.setText(null);
家庭住址.setText(null);
出生.setText(null);
}
}
else
{
录入修改.setEnabled(false);
Stringwarning="必须要输入学号!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
学号.setText(null);
姓名.setText(null);
所学专业.setText(null);
家庭住址.setText(null);
出生.setText(null);
}
}
elseif(e.getSource()==录入修改)
{
Stringnumber="";
number=学号.getText();
if(number.length()>0)
{
try{
inOne=newFileInputStream(file);
inTwo=newObjectInputStream(inOne);
基本信息表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exceptionee)
{
}
if(基本信息表.containsKey(number))
{
Stringquestion="该生基本信息已存在,您想修改他(她)的基本信息吗?";JOptionPane.showMessageDialog(this,question,"警告",JOptionPane.QUESTION_MESSAGE);
Stringm="基本信息将被修改!";
intok=JOptionPane.showConfirmDialog(this,m,"确认",J
上一篇:
JAVA班主任管理系统(论文和程序)
下一篇:
试题库管理系统毕业论文