⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showadmin.java

📁 自己编的学籍管理系统
💻 JAVA
字号:
package myprojects.studymanager;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;



public class ShowAdmin extends JFrame implements ActionListener
{
	JRadioButton jbutton1,jbutton2;
	JButton button,close;
	JRadioButton name,major,ID;
	JTextField nametext,IDtext; 
	JComboBox majorComboBox;
	JList list;
	DefaultListModel Items;
	Box box1,box2,box3,box4,box5,dbox,abox,bbox,sbox;
	File mfile,sfile,tfile;
	ShowStudent studentf;
	ShowTeacher teacherf; 
	
	LinkedList majorlist;
	Major majorsearch;
	LinkedList teacher;
	LinkedList student;
	ConcreteStudentManager manager;
	StudyManager motherp;
	AbstractStudent abstractStudent;
	JScrollPane listPane;
	
	ShowAdmin(StudyManager frame)
	{
		this.setSize(500,450);
    	motherp=frame;	   		
    	Point p=frame.getLocation();		//定位dialog在母版中间
    	//Dimension s=frame.getSize();
    	int x=(int)p.getX();
    	int y=(int)p.getY();
    	//int sx=(int)s.getWidth();
    	//int sy=(int)s.getHeight();
    	//x=x+sx/2-300/2;
    	//y=y+sy/2-200/2;
    	this.setLocation(x,y);
    	motherp.setVisible(false);
    	
    	
		mfile=new File(".\\data\\Major.study");
		tfile=new File(".\\data\\Teacher.study");
		sfile=new File(".\\data\\Student.study");
		
    	Container cp=this.getContentPane();
    	
    	
		jbutton1=new JRadioButton("学生",true);
		jbutton1.addActionListener(this);
		jbutton2=new JRadioButton("导师");
		jbutton2.addActionListener(this);
		ButtonGroup buttongroup=new ButtonGroup();
		buttongroup.add(jbutton1);
		buttongroup.add(jbutton2);
		
		ID=new JRadioButton("ID",true);
		ID.addActionListener(this);
		name=new JRadioButton("名字:");
		name.addActionListener(this);
		major=new JRadioButton("专业");
		major.addActionListener(this);
		ButtonGroup buttongroup1=new ButtonGroup();
		buttongroup1.add(ID);
		buttongroup1.add(name);
		buttongroup1.add(major);
		
		
		
		button=new JButton("查找");
		close=new JButton("关闭");
		close.addActionListener(this);
		button.addActionListener(this);
		nametext=new JTextField(10);
		nametext.setEditable(false);
		IDtext=new JTextField(10);
		majorComboBox=new JComboBox();
		majorComboBox.setEnabled(false);
		try
		{
    		FileInputStream input1=new FileInputStream(mfile);
			ObjectInputStream input2=new ObjectInputStream(input1);
			majorlist=(LinkedList)input2.readObject();
			input1.close();
			input2.close();
				
			ListIterator majoriterator=majorlist.listIterator();
			while(majoriterator.hasNext())
			{
				Major addmajor=(Major)majoriterator.next();
				majorComboBox.addItem(addmajor);
			}		
				
		}
		catch(Exception mmee)
		{
			mmee.printStackTrace();
		}
		
		Items=new DefaultListModel();
		Items.add(0," DEFAULT");
		list=new JList(Items);
		list.setSelectedIndex(0);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		listPane = new JScrollPane(list);
		listPane.setSize(20,20);
	    	  
		class ListListener implements ListSelectionListener
		{
			public void valueChanged(ListSelectionEvent e)
			{
				String s=(String)list.getSelectedValue();
				if(s.equals(" DEFAULT"))
				{}
				else
				{
				if(jbutton1.isSelected())
					studentf.setStudent(s);
				else if(jbutton2.isSelected())
					teacherf.setTeacher(s);
				}
				
				
			}
			
		}
		list.addListSelectionListener(new ListListener());
		
		studentf=new ShowStudent(motherp);
		teacherf=new ShowTeacher(motherp);
		
		
		
		box1=Box.createHorizontalBox();
		box1.add(jbutton1);
		box1.add(jbutton2);
		
		box2=Box.createHorizontalBox();
		box2.add(name);
		box2.add(nametext);
		
		
		box3=Box.createHorizontalBox();
		box3.add(major);
		box3.add(majorComboBox);
		
		
		box4=Box.createHorizontalBox();
		box4.add(ID);
		box4.add(IDtext);
		
		box5=Box.createHorizontalBox();
		box5.add(button);
		box5.add(close);
		
	
		sbox=Box.createHorizontalBox();
		sbox.add(studentf);
		sbox.add(teacherf);
		studentf.setVisible(true);
		studentf.adminuse();
		teacherf.setVisible(false);
		teacherf.adminuse();
		
		JPanel b=new JPanel();
		b.setLayout(new FlowLayout());
		b.add(sbox);
		
		JPanel c=new JPanel();
		c.setLayout(new FlowLayout());
		c.add(listPane);
		
		dbox=Box.createHorizontalBox();
		dbox.add(c);
		dbox.add(b);
		
		
		
		abox=Box.createVerticalBox();
		abox.add(box1);
		abox.add(box4);
		abox.add(box2);
		abox.add(box3);
		abox.add(box5);
		JPanel a=new JPanel();
		a.add(abox); 
		
		bbox=Box.createVerticalBox();
		bbox.add(a);
		bbox.add(dbox);
		
		cp.add(bbox);
		this.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				motherp.setVisible(true);
				dispose();
			}
		});
		this.setVisible(true);
		
			
	}
	public void actionPerformed(ActionEvent se)
	{
		if(se.getSource()==jbutton2)
		{
			try
			{
				Items.removeAllElements();
			}
			catch(Exception he)
			{}
			Items.add(0," DEFAULT");
			list.setSelectedIndex(0);
			studentf.setVisible(false);
			teacherf.setVisible(true);
			teacherf.defaultValue();
			
			major.setSelected(true);
			majorComboBox.setEnabled(true);
			box2.setVisible(false);
			box4.setVisible(false);
		}
		else if(se.getSource()==jbutton1)
		{
			try
			{
				Items.removeAllElements();
			}
			catch(Exception he)
			{}
			Items.add(0," DEFAULT");
			list.setSelectedIndex(0);
			studentf.setVisible(true);
			studentf.defaultValue();
			teacherf.setVisible(false);
			
			ID.setSelected(true);
			IDtext.setEditable(true);
			majorComboBox.setEnabled(false);
			box2.setVisible(true);
			box4.setVisible(true);
		}
		else if(se.getSource()==ID)
		{
			nametext.setEditable(false);
			nametext.setText("");
			majorComboBox.setEnabled(false);
			IDtext.setEditable(true);
		}
		else if(se.getSource()==name)
		{
			IDtext.setEditable(false);
			IDtext.setText("");
			majorComboBox.setEnabled(false);
			nametext.setEditable(true);
		}
		else if(se.getSource()==major)
		{
			nametext.setEditable(false);
			IDtext.setEditable(false);
			majorComboBox.setEnabled(true);
		}
		else if(se.getSource()==close)
		{
			motherp.setVisible(true);
			this.dispose();	
		}
		else if(se.getSource()==button)
		{
			if(jbutton1.isSelected())
			{
				studentf.setVisible(true);
				
				if(ID.isSelected())
				{
					if(IDtext.getText()=="")
					{
						JOptionPane.showMessageDialog(this,
							"Imput the ID!","Warning",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
					try
					{
						FileInputStream input3=new FileInputStream(sfile);
						ObjectInputStream input4=new ObjectInputStream(input3);
						manager=
							(ConcreteStudentManager)input4.readObject();
						input3.close();
						input4.close();
						abstractStudent=(AbstractStudent)manager.IDsearchStudent(IDtext.getText());
						studentf.setStudent(IDtext.getText());
						try
						{
							Items.removeAllElements();
						}
						catch(Exception he)
						{}
						Items.add(0,abstractStudent.getS_studentID());
						list.setSelectedIndex(0);
						
						
					}
					catch(StudentNotFoundException fe)
					{
						JOptionPane.showMessageDialog(this,
							"Student not found!","Warning",JOptionPane.ERROR_MESSAGE);
					}
					catch(Exception ee)
					{
						ee.printStackTrace();
					}
					}
									
				}
				else if(name.isSelected())
				{
					if(nametext.getText()=="")
					{
						JOptionPane.showMessageDialog(this,
							"Imput the Name!","Warning",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
					try
					{
						FileInputStream input3=new FileInputStream(sfile);
						ObjectInputStream input4=new ObjectInputStream(input3);
						manager=
							(ConcreteStudentManager)input4.readObject();
						input3.close();
						input4.close();
						abstractStudent=(AbstractStudent)manager.NamesearchStudent(nametext.getText());
						studentf.setStudent(abstractStudent.getS_studentID());
						try
						{
							Items.removeAllElements();
						}
						catch(Exception he)
						{}
						Items.add(0,abstractStudent.getS_studentID());
						list.setSelectedIndex(0);
						
					}
					catch(StudentNotFoundException fe)
					{
						JOptionPane.showMessageDialog(this,
							"Student not found!","Warning",JOptionPane.ERROR_MESSAGE);
					}
					catch(Exception ee)
					{
						ee.printStackTrace();
					}
					}
			
				}
				else if(major.isSelected())
				{
					
					try
					{
						try
						{
							Items.removeAllElements();
						}
						catch(Exception he)
						{}
						majorsearch=(Major)majorComboBox.getSelectedItem();
						student=majorsearch.getM_student();
						ListIterator studentIterator=student.listIterator();
						while(studentIterator.hasNext())
						{
							Items.add(0,(studentIterator.next()));
						}
						
						if(student.size()!=0)
						{
							list.setSelectedIndex(0);
							studentf.setStudent((String)(student.getLast()));
						}
						else if(student.size()==0)
						{
							JOptionPane.showMessageDialog(this,
							"No Student In This Major!","Warning",JOptionPane.ERROR_MESSAGE);
						}
				
					}
					catch(Exception ee)
					{
						//ee.printStackTrace();
					}
		
				}
			}
			else if(jbutton2.isSelected())
			{
				teacherf.setVisible(true);
				try
				{
					Items.removeAllElements();
				}
				catch(Exception he)
				{}
				try
				{
					majorsearch=(Major)majorComboBox.getSelectedItem();
					teacher=majorsearch.getM_teacher();
					ListIterator teacherIterator=teacher.listIterator();
					while(teacherIterator.hasNext())
					{
						
						Items.add(0,(teacherIterator.next()));
					}
					if(teacher.size()!=0)
					{
						list.setSelectedIndex(0);
						teacherf.setTeacher((String)(teacher.getLast()));
					}
					else if(teacher.size()==0)
					{
						JOptionPane.showMessageDialog(this,
							"No Teacher In This Major!","Warning",JOptionPane.ERROR_MESSAGE);
					}
				
				}
				catch(Exception ee)
				{
					//ee.printStackTrace();
				}
				
			}
			
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -