package classManager;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import javax.swing.filechooser.*;
@SuppressWarnings("serial")
public class ModifySituation extends JFrame implements ActionListener{
TeacherPicture pic;
HashMap<String,Class> BaseInformation=new HashMap<String,Class>();
JTextField classnumber,headteacher,population;
JComboBox discipling,college;
JButton selectpic;
ButtonGroup group=null;
JButton beginmodify,inputmodify,reset;
RandomAccessFile in=null;
RandomAccessFile out=null;
File systemFile,imagePic;
JComboBox oldMess;
Class tec=null;
String path;
String college1[]={"信工学院","人文学院","建筑学院"};
@SuppressWarnings("unused")
public ModifySituation(File file){
super("修改班级基本信息对话框");
Container c=getContentPane();
tec=new Class();
systemFile=file;
pic=new TeacherPicture();
classnumber=new JTextField(6);
headteacher=new JTextField(6);
discipling=new JComboBox();
try{
FileReader inOne=new FileReader("专业.txt");
BufferedReader inTwo=new BufferedReader(inOne);
String s=null;
int i=0;
while((s=inTwo.readLine())!=null)
discipling.addItem(s);
inOne.close();
inTwo.close();
}
catch(IOException exp){
discipling.addItem("网络工程");
discipling.addItem("计算机科学与技术");
discipling.addItem("数字媒体技术");
discipling.addItem("卓越工程师");
}
college=new JComboBox(college1);
population=new JTextField(6);
selectpic=new JButton("选择");
oldMess=new JComboBox();
beginmodify=new JButton("开始修改");
inputmodify=new JButton("录入修改");
inputmodify.setEnabled(false);
selectpic.setEnabled(false);
reset=new JButton("重置");
classnumber.addActionListener(this);
beginmodify.addActionListener(this);
inputmodify.addActionListener(this);
reset.addActionListener(this);
selectpic.addActionListener(this);
Box box1=Box.createHorizontalBox();
box1.add(new JLabel("输入要修改信息的班号:",JLabel.CENTER));
box1.add(classnumber);
box1.add(beginmodify);
Box box2=Box.createHorizontalBox();
box2.add(new JLabel("(新)班主任:",JLabel.CENTER));
box2.add(headteacher);
Box box3=Box.createHorizontalBox();
box3.add(new JLabel("(新)学院:",JLabel.CENTER));
box3.add(college);
Box box4=Box.createHorizontalBox();
box4.add(new JLabel("(新)专业:",JLabel.CENTER));
box4.add(discipling);
Box box5=Box.createHorizontalBox();
box5.add(new JLabel("(新)人数:",JLabel.CENTER));
box5.add(population);
Box box6=Box.createHorizontalBox();
box6.add(new JLabel("已有的班级数据:",JLabel.CENTER));
box6.add(oldMess);
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 picPanel=new JPanel();
picPanel.setBackground(null);
picPanel.add(new JLabel("选择照片:",JLabel.CENTER));
picPanel.add(selectpic);
JPanel putButton=new JPanel();
putButton.setBackground(null);
putButton.add(inputmodify);
putButton.add(reset);
JPanel messPanel=new JPanel();
messPanel.setBackground(null);
messPanel.add(boxH);
setLayout(new BorderLayout());
JSplitPane splitV=new JSplitPane(JSplitPane.VERTICAL_SPLIT,picPanel,pic);
JSplitPane splitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,messPanel,splitV);
c.add(splitH,BorderLayout.CENTER);
c.add(putButton,BorderLayout.SOUTH);
setSize(480,270);
setVisible(true);
validate();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public void actionPerformed(ActionEvent e){
if(e.getSource()==beginmodify||e.getSource()==classnumber){
oldMess.removeAllItems();
String number="";
imagePic=null;
tec=null;
Class temp;
String inf=new String();
String[] s2=new String[6];
number=classnumber.getText();
if(number.length()>0){
try{
RandomAccessFile in=new RandomAccessFile(systemFile,"r");
while((inf=in.readUTF())!=null){//注意:文本文件中一定要按照Class中定义的数据成员的顺序写入,否则此方法无效
s2[0]=inf;
for(int i=1;i<6;i++){
s2[i]=in.readUTF();
temp=new Class(s2[0],s2[1],s2[2],s2[3],s2[4],s2[5]);
BaseInformation.put(s2[0], temp);
}
}
in.close();
}
catch(Exception ee){}
if(BaseInformation.containsKey(number)){
inputmodify.setEnabled(true);
selectpic.setEnabled(true);
tec=BaseInformation.get(number);
oldMess.addItem("班主任:"+tec.getName());
oldMess.addItem("学院:"+tec.getCollege());
oldMess.addItem("专业:"+tec.getDiscipling());
oldMess.addItem("人数:"+tec.getPopulation());
path=tec.getImagePic();
pic.setImage(new File(path));
pic.repaint();
headteacher.setText(tec.getName());
college.setSelectedItem(tec.getCollege());
population.setText(tec.getPopulation());
discipling.setSelectedItem(tec.getDiscipling());
}
else{
inputmodify.setEnabled(false);
selectpic.setEnabled(false);
String warning="该班级不存在!";
JOptionPane.showMessageDialog(this, warning,"警告",JOptionPane.WARNING_MESSAGE);
clearMess();
}
}
else{
inputmodify.setEnabled(false);
selectpic.setEnabled(false);
String warning="必须要输入班号!";
JOptionPane.showMessageDialog(this, warning,"警告",JOptionPane.WARNING_MESSAGE);
clearMess();
}
}
else if(e.getSource()==inputmodify){
String number="";
Class temp;
String inf=new String();
String[] s2=new String[6];
number=classnumber.getText();
if(number.length()>0){
try{
RandomAccessFile in=new RandomAccessFile(systemFile,"r");
while((inf=in.readUTF())!=null){//注意:文本文件中一定要按照Class中定义的数据成员的顺序写入,否则此方法无效
s2[0]=inf;
for(int i=1;i<6;i++){
s2[i]=in.readUTF();
temp=new Class(s2[0],s2[1],s2[2],s2[3],s2[4],s2[5]);
BaseInformation.put(s2[0], temp);
}
}
in.close();
}
catch(Exception ee){}
if(BaseInformation.containsKey(number)){
String question="该班主任基本信息已存在,您想修改他(她)的信息么?";
JOptionPane.showMessageDialog(this, question,"警告",JOptionPane.QUESTION_MESSAGE);
String m="基本信息将被修改!";
int ok=JOptionPane.showConfirmDialog(this, m,"确认",JOptionPane.INFORMATION_MESSAGE);
if(ok==JOptionPane.YES_OPTION){
String name=headteacher.getText();
if(name.length()==0)
name=tec.getName();
String disci=(String)discipling.getSelectedItem();
if(discipling==null)
disci=tec.getDiscipling();
String col=(String)college.getSelectedItem();
if(col.length()==0)
col=tec.getCollege();
String popu=population.getText();
if(popu.length()==0)
popu=tec.getPopulation();
if(imagePic==null)
path=tec.getImagePic();
tec=new Class();
tec.setNumber(number);
tec.setName(name);
tec.setCollege(col);
tec.setDiscipling(disci);
tec.setPopulation(popu);
tec.setImagePic(path);
BaseInformation.put(number, tec);
try{
RandomAccessFile out=new RandomAccessFile(systemFile,"rw");
out.setLength(0);
Set set=BaseInformation.entrySet();
Iterator i=set.iterator();
while(i.hasNext()){
Map.Entry<String, Class> map=(Map.Entry<String, Class>)i.next();
Class temp1=new Class();
temp1=map.getValue();
out.writeUTF(temp1.getNumber());
out.writeUTF(temp1.getHeadteacher());
out.writeUTF(temp1.getCollege());
out.writeUTF(temp1.getDiscipling());
out.writeUTF(temp1.getPopulation());
out.w
学生管理系统/班级管理系统
需积分: 35 9 浏览量
2013-03-14
16:05:05
上传
评论 5
收藏 11KB ZIP 举报
逆浮天晟
- 粉丝: 0
- 资源: 2
最新资源
- alu.v
- H21-282学习参考.pdf
- QuestionTwo.java
- QuestionOne.java
- AWS Certified Solutions Architect Study Guide -SAA-C03 .docx
- 校园小情书微信小程序源码 社区小程序前后端开源 校园表白墙交友小程序.rar
- OA办公自动化管理系统(Struts1.2+Hibernate3.0+Spring2+DWR).rar
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈