📄 showteacher.java
字号:
package myprojects.studymanager;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class ShowTeacher extends JPanel implements ActionListener
{
File file;
JTextField text1,text2,text3,text4,text5,texti;
JTextArea text6;
String s1,s2,s3,s4,s5,s6,si;
JButton button1,button2;
JButton choose; //choose student
JLabel title,label1,label2,label3,label4,label5,label6,labeli;
JButton search;
Teacher teacher;
String tID;
StudyManager motherp;
LinkedList teacherlist;
ShowTeacher(StudyManager m)
{
motherp=m;
file=new File(".\\data\\Teacher.study");
label1=new JLabel("姓名:");
text1=new JTextField(10);
Box box1=Box.createHorizontalBox();
box1.add(label1);
box1.add(text1);
label2=new JLabel("工号:");
text2=new JTextField(10);
text2.setEditable(false);
Box box2=Box.createHorizontalBox();
box2.add(label2);
box2.add(text2);
label3=new JLabel("学院:");
text3=new JTextField(10);
Box box3=Box.createHorizontalBox();
box3.add(label3);
box3.add(text3);
label4=new JLabel("专业:");
text4=new JTextField(10);
text4.setEditable(false);
Box box4=Box.createHorizontalBox();
box4.add(label4);
box4.add(text4);
label5=new JLabel("学历:");
text5=new JTextField(10);
labeli=new JLabel("年龄:");
texti=new JTextField(2);
Box box5=Box.createHorizontalBox();
box5.add(label5);
box5.add(text5);
box5.add(labeli);
box5.add(texti);
label6=new JLabel("个人简介");
Box box6=Box.createHorizontalBox();
box6.add(label6);
box6.add(new JLabel(""));
text6=new JTextArea(3,20);
Box box7=Box.createHorizontalBox();
box7.add(new JLabel(" "));
box7.add(text6);
button1=new JButton("修改");
button1.addActionListener(this);
button2=new JButton("注销");
button2.addActionListener(this);
choose=new JButton("选学生");
choose.addActionListener(this);
search=new JButton("查找");
search.addActionListener(this);
Box box8=Box.createHorizontalBox();
box8.add(button1);
box8.add(choose);
box8.add(search);
box8.add(button2);
title=new JLabel("");
Font font=new Font(null,Font.BOLD,15);
title.setFont(font);
Box box9=Box.createHorizontalBox();
box9.add(title);
Box box=Box.createVerticalBox();
box.add(Box.createVerticalStrut(30));
box.add(box9);
box.add(Box.createVerticalStrut(10));
box.add(box1);
box.add(Box.createVerticalStrut(3));
box.add(box2);
box.add(Box.createVerticalStrut(3));
box.add(box3);
box.add(Box.createVerticalStrut(3));
box.add(box4);
box.add(Box.createVerticalStrut(3));
box.add(box5);
box.add(Box.createVerticalStrut(3));
box.add(box6);
box.add(Box.createVerticalStrut(3));
box.add(box7);
box.add(Box.createVerticalStrut(5));
box.add(box8);
this.setLayout(new FlowLayout());
add(box);
}
public void setTeacher(String ID)
{
tID=ID;
try
{
FileInputStream input3=new FileInputStream(file);
ObjectInputStream input4=new ObjectInputStream(input3);
teacherlist=
(LinkedList)input4.readObject();
input3.close();
input4.close();
ListIterator tea=teacherlist.listIterator();
while(tea.hasNext())
{
Teacher next=(Teacher)tea.next();
if(next.getT_ID().equals(tID))
{
teacher=next;
break;
}
}
}
catch(Exception ee)
{
ee.printStackTrace();
}
title.setText(teacher.getT_name()+",您的信息如下");
s1=teacher.getT_name();
text1.setText(s1);
s2=teacher.getT_ID();
text2.setText(s2);
s3=teacher.getT_department();
text3.setText(s3);
s4=teacher.getT_major();
text4.setText(s4);
s5=teacher.getT_status();
text5.setText(s5);
s6=teacher.getT_information();
text6.setText(s6);
si=""+teacher.getT_age();
texti.setText(si);
//motherp.setSize(400,350);
}
public void adminuse()
{
title.setVisible(false);
button2.setVisible(false);
choose.setVisible(false);
search.setVisible(false);
}
public void unmodifiable()
{
title.setVisible(false);
text1.setEditable(false);
text2.setEditable(false);
text3.setEditable(false);
text4.setEditable(false);
text5.setEditable(false);
texti.setEditable(false);
text6.setEnabled(false);
button1.setVisible(false);
button2.setVisible(false);
choose.setVisible(false);
search.setVisible(false);
}
public void defaultValue()
{
text1.setText("");
text2.setText("");
text3.setText("");
text4.setText("");
text5.setText("");
text6.setText("");
texti.setText("");
}
public void actionPerformed(ActionEvent te)
{
if(te.getSource()==choose)
{
new ChooseStudent(motherp,teacher).show();
}
else if(te.getSource()==search)
{
new Searchframe(motherp).show();
}
else if(te.getSource()==button2)
{
title.setText("");
text1.setText("");
text2.setText("");
text3.setText("");
text4.setText("");
text5.setText("");
text6.setText("");
texti.setText("");
try
{
FileOutputStream one=new FileOutputStream(file);
ObjectOutputStream two=new ObjectOutputStream(one);
two.writeObject(teacherlist);
one.close();
two.close();
}
catch(Exception ke)
{}
motherp.setCardlogin();
}
else if(te.getSource()==button1)
{
Object[]options={"是","否","取消"};
int i=
JOptionPane.showOptionDialog(this,"确定修改资料?","Option",
JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null,
options,null);
if(i==0)
{
try
{
String name=text1.getText();
int age=new Integer(texti.getText()).intValue();
String department=text3.getText();
String major=text4.getText();
String status=text5.getText();
String information=text6.getText();
teacher.setT_name(name);
teacher.setT_age(age);
teacher.setT_department(department);
teacher.setT_major(major);
teacher.setT_status(status);
teacher.setT_information(information);
FileOutputStream one=new FileOutputStream(file);
ObjectOutputStream two=new ObjectOutputStream(one);
two.writeObject(teacherlist);
one.close();
two.close();
}
catch(Exception eee)
{
eee.printStackTrace();
}
}
else if(i==1)
{
try
{
s1=teacher.getT_name();
text1.setText(s1);
s3=teacher.getT_department();
text3.setText(s3);
s4=teacher.getT_major();
text4.setText(s4);
s5=teacher.getT_status();
text5.setText(s5);
s6=teacher.getT_information();
text6.setText(s6);
si=""+teacher.getT_age();
texti.setText(si);
}
catch(Exception tte)
{
tte.printStackTrace();
}
}
else
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -