📄 showstudent.java
字号:
package myprojects.studymanager;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class ShowStudent extends JPanel implements ActionListener
{
File file;
JTextField text1,text2,text3,text4,text5;
JComboBox text6,text7;
String s1,s2,s3,s4,s5;
int s6,s7;
JButton button1,button2;
JButton choose; //选系选导师
JLabel title,label1,label2,label3,label4,label5,label6,label7,label8;
JButton search;
AbstractStudent abstractStudent;
StudyManager motherp;
String sID;
ConcreteStudentManager manager;
ShowStudent(StudyManager m)
{
motherp=m;
file=new File(".\\data\\Student.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);
choose=new JButton("选系");
choose.addActionListener(this);
Box box4=Box.createHorizontalBox();
box4.add(label4);
box4.add(text4);
box4.add(choose);
label5=new JLabel("年龄:");
text5=new JTextField(2);
label6=new JLabel("入学时间:");
text6=new JComboBox();
int temp;
for(int i=0;i<=7;i++)
{
temp=2004-i;
text6.addItem(""+temp);
}
label7=new JLabel("年");
text7=new JComboBox();
for(int i=1;i<=12;i++)
text7.addItem(""+i);
label8=new JLabel("月");
Box box5=Box.createHorizontalBox();
box5.add(label5);
box5.add(text5);
box5.add(label6);
box5.add(text6);
box5.add(label7);
box5.add(text7);
box5.add(label8);
button1=new JButton("修改");
button1.addActionListener(this);
search=new JButton("查找");
search.addActionListener(this);
button2=new JButton("注销");
button2.addActionListener(this);
Box box6=Box.createHorizontalBox();
box6.add(button1);
box6.add(search);
box6.add(button2);
title=new JLabel(" ");
Font font=new Font(null,Font.BOLD,15);
title.setFont(font);
Box box7=Box.createHorizontalBox();
box7.add(title);
Box box=Box.createVerticalBox();
box.add(Box.createVerticalStrut(30));
box.add(box7);
box.add(Box.createVerticalStrut(10));
box.add(box1);
box.add(Box.createVerticalStrut(5));
box.add(box2);
box.add(Box.createVerticalStrut(5));
box.add(box3);
box.add(Box.createVerticalStrut(5));
box.add(box4);
box.add(Box.createVerticalStrut(5));
box.add(box5);
box.add(Box.createVerticalStrut(10));
box.add(box6);
this.setLayout(new FlowLayout());
add(box);
}
public void setStudent(String ID)
{
sID=ID;
try
{
FileInputStream input3=new FileInputStream(file);
ObjectInputStream input4=new ObjectInputStream(input3);
manager=
(ConcreteStudentManager)input4.readObject();
input3.close();
input4.close();
abstractStudent=(AbstractStudent)manager.IDsearchStudent(ID);
}
catch(Exception ee)
{
ee.printStackTrace();
}
s1=abstractStudent.getS_name();
text1.setText(s1);
s2=abstractStudent.getS_studentID();
text2.setText(s2);
s3=abstractStudent.getS_department();
text3.setText(s3);
s5=""+abstractStudent.getS_age();
text5.setText(s5);
s6=abstractStudent.getEnrollmentYear().getYear();
text6.setSelectedIndex(2004-s6);
s7=abstractStudent.getEnrollmentYear().getMonth();
text7.setSelectedIndex(s7-1);
if(abstractStudent instanceof BachlorStudent)
{
title.setText("本科生"+s1+",您的信息如下");
if((((BachlorStudent)abstractStudent).hasMajor())==true)
{
choose.setEnabled(false);
text4.setText(((BachlorStudent)abstractStudent).getMajor().toString());
}
}
else if(abstractStudent instanceof GraStudent)
{
title.setText("研究生"+s1+"你的信息如下");
label4.setText("导师");
choose.setText("选择");
if((((GraStudent)abstractStudent).hasTeacher())==1)
{
choose.setEnabled(false);
text4.setText(((GraStudent)abstractStudent).getTeacher().toString()+
" (未定)");
}
else if((((GraStudent)abstractStudent).hasTeacher())==2)
{
choose.setEnabled(false);
text4.setText(((GraStudent)abstractStudent).getTeacher().toString());
}
else if((((GraStudent)abstractStudent).hasTeacher())==3)
{
text4.setText(((GraStudent)abstractStudent).getTeacher().toString()+
" (被拒)");
choose.setText("重选");
}
}
}
public void adminuse()
{
title.setVisible(false);
button2.setVisible(false);
choose.setVisible(false);
search.setVisible(false);
}
public void unmodifiable()
{
title.setVisible(false);
text1.setEditable(false);
text1.setText("");
text2.setEditable(false);
text2.setText("");
text3.setEditable(false);
text3.setText("");
text4.setEditable(false);
text4.setText("");
text5.setEditable(false);
text5.setText("");
text7.setEnabled(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.setSelectedIndex(0);
text7.setSelectedIndex(0);
}
public void actionPerformed(ActionEvent bse)
{
if(bse.getSource()==choose)
{
try
{
if(abstractStudent instanceof BachlorStudent)
{
((BachlorStudent)abstractStudent).selectMajor(motherp).selectpanel();
if(((BachlorStudent)abstractStudent).hasMajor()==true)
{
text4.setText(((BachlorStudent)abstractStudent).getMajor().toString());
choose.setEnabled(false);
}
}
if(abstractStudent instanceof GraStudent)
{
((GraStudent)abstractStudent).selectTeacher(motherp).selectpanel();
if((((GraStudent)abstractStudent).hasTeacher())==1)
{
choose.setEnabled(false);
text4.setText(((GraStudent)abstractStudent).getTeacher().toString()+
" (未定)");
}
}
FileOutputStream one=new FileOutputStream(file);
ObjectOutputStream two=new ObjectOutputStream(one);
two.writeObject(manager);
one.close();
two.close();
}
catch(Exception xxe)
{
xxe.printStackTrace();
}
}
else if(bse.getSource()==button2)
{
text4.setText("");
choose.setEnabled(true);
motherp.setCardlogin();
}
else if(bse.getSource()==search)
{
new Searchframe(motherp).show();
}
else if(bse.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(text5.getText()).intValue();
String studentID=text2.getText();
String department=text3.getText();
int year=2004-text6.getSelectedIndex();
int month=text7.getSelectedIndex()+1;
En_time time=new En_time(year,month);
abstractStudent.setS_name(name);
abstractStudent.setS_age(age);
abstractStudent.setS_studentID(studentID);
abstractStudent.setS_department(department);
abstractStudent.setEnrollmentYear(time);
FileOutputStream one=new FileOutputStream(file);
ObjectOutputStream two=new ObjectOutputStream(one);
two.writeObject(manager);
one.close();
two.close();
}
catch(Exception eee)
{
eee.printStackTrace();
}
}
else if(i==1)
{
try
{
s3=abstractStudent.getS_department();
text3.setText(s3);
s5=""+abstractStudent.getS_age();
text5.setText(s5);
s6=abstractStudent.getEnrollmentYear().getYear();
text6.setSelectedIndex(2004-s6);
s7=abstractStudent.getEnrollmentYear().getMonth();
text7.setSelectedIndex(s7-1);
}
catch(Exception te)
{
te.printStackTrace();
}
}
else
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -