import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class Change extends JPanel implements ActionListener
{
Hashtable 基本信息表;
JTextField no,name,zhuanye,grade,birth;
JRadioButton 男,女;
ButtonGroup group;
JButton 修改,录入修改,重置;
FileInputStream inOne;
ObjectInputStream inTwo;
FileOutputStream outOne;
ObjectOutputStream outTwo;
File file;
public Change(File file)
{
this.file=file;
no=new JTextField(10);
name=new JTextField(10);
zhuanye=new JTextField(10);
grade=new JTextField(10);
birth=new JTextField(10);
group=new ButtonGroup();
男=new JRadioButton("男",true);
女=new JRadioButton("女",false);
group.add(男);
group.add(女);
修改=new JButton("确定修改");
录入修改=new JButton("录入修改");
录入修改.setEnabled(false);
重置=new JButton("重置");
no.addActionListener(this);
修改.addActionListener(this);
录入修改.addActionListener(this);
重置.addActionListener(this);
Box box1=Box.createHorizontalBox();
box1.add(new JLabel("输入要修改的学号:",JLabel.CENTER));
box1.add(no);
box1.add(修改);
Box box2=Box.createHorizontalBox();
box2.add(new JLabel("姓名:",JLabel.CENTER));
box2.add(name);
Box box3=Box.createHorizontalBox();
box3.add(new JLabel("性别:",JLabel.LEFT));
box3.add(男);
box3.add(女);
Box box4=Box.createHorizontalBox();
box4.add(new JLabel("专业:",JLabel.CENTER));
box4.add(zhuanye);
Box box5=Box.createHorizontalBox();
box5.add(new JLabel("年级:",JLabel.CENTER));
box5.add(grade);
Box box6=Box.createHorizontalBox();
box6.add(new JLabel("出生:",JLabel.CENTER));
box6.add(birth);
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);
JPanel pSouth=new JPanel();
pSouth.add(录入修改);
pSouth.add(重置);
add(pSouth,BorderLayout.SOUTH);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==修改||e.getSource()==no)
{
String number="";
number=no.getText();
if(number.length()>0)
{
try {
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
基本信息表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee)
{
}
if(基本信息表.containsKey(number))
{
录入修改.setEnabled(true);
Student stu=(Student)基本信息表.get(number);
name.setText(stu.getName());
zhuanye.setText(stu.getDisciping());
grade.setText(stu.getGrade());
birth.setText(stu.getBorth());
if(stu.getSex().equals("男"))
{
男.setSelected(true);
}
else
{
女.setSelected(true);
}
}
else
{
录入修改.setEnabled(false);
String warning="该学号不存在!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
no.setText(null);
name.setText(null);
zhuanye.setText(null);
grade.setText(null);
birth.setText(null);
}
}
else
{
录入修改.setEnabled(false);
String warning="必须要输入学号!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
no.setText(null);
name.setText(null);
zhuanye.setText(null);
grade.setText(null);
birth.setText(null);
}
}
else if(e.getSource()==录入修改)
{
String number="";
number=no.getText();
if(number.length()>0)
{
try {
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
基本信息表=(Hashtable)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 name1=name.getText();
String discipling=zhuanye.getText();
String grade1=grade.getText();
String borth1=birth.getText();
String sex=null;
if(男.isSelected())
{
sex=男.getText();
}
else
{
sex=女.getText();
}
Student 学生=new Student();
学生.setNumber(number);
学生.setName(name1);
学生.setDiscipling(discipling);
学生.setGrade(grade1);
学生.setBorth(borth1);
学生.setSex(sex);
try
{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
基本信息表.put(number,学生);
outTwo.writeObject(基本信息表);
outTwo.close();
outOne.close();
no.setText(null);
name.setText(null);
zhuanye.setText(null);
grade.setText(null);
birth.setText(null);
}
catch(Exception ee)
{
System.out.println(ee);
}
录入修改.setEnabled(false);
}
else if(ok==JOptionPane.NO_OPT
Java开发的学生信息管理系统
需积分: 0 138 浏览量
2008-12-22
17:50:01
上传
评论 1
收藏 8KB RAR 举报
JONY1215225
- 粉丝: 0
- 资源: 4
最新资源
- juhua-p8YYy-v0e13a7b5(1).apk
- Neo4j资源:Neo4j.rb的性能测试相关程序
- 排序算法之堆排序算法:用C++语言实现堆排序算法
- 基于Springboot的房屋租赁系统(源代码+论文+说明文档+PPT)-计算机专业精品毕业设计和课程设计
- leidian.py
- 直接插入排序算法:C语言实现直接插入排序算法
- 基于Springboot的大学生就业招聘系统(源代码+论文+说明文档+PPT)-计算机专业精品毕业设计和课程设计
- 基于Vue的H5结婚请帖前端设计源码
- saxaxasxasx
- 基于SSM++jsp的实验室耗材管理系统(源代码+论文+说明文档+PPT)-计算机专业精品毕业设计和课程设计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0