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

📄 choosestudent.java

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


public class ChooseStudent extends JDialog implements ActionListener
{
	ShowStudent studentf;
	JList list;
	DefaultListModel Items;
	File sfile;
	JButton choose,deny,close;
	
	StudyManager motherp;
	Teacher teacher;
	LinkedList student;
	JScrollPane listPane;
	
	ChooseStudent(StudyManager frame,Teacher t)
	{
		sfile=new File(".\\data\\Student.study");
		motherp=frame;
		teacher=t;
		this.setSize(500,400);
    	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);
    	
    	Container cp=this.getContentPane();
    	cp.setLayout(new FlowLayout());
    	
    	
    	
    	Items=new DefaultListModel();
		list=new JList(Items);
		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
				{
				studentf.setStudent(s);
				try
				{
					FileInputStream input1=new FileInputStream(sfile);
					ObjectInputStream input2=new ObjectInputStream(input1);
					ConcreteStudentManager manger=
						(ConcreteStudentManager)input2.readObject();
						input1.close();
					input2.close();
					GraStudent st=(GraStudent)manger.IDsearchStudent(s);
					if(st.hasTeacher()==2||st.hasTeacher()==3)
					{
						choose.setEnabled(false);
						deny.setEnabled(false);
					}
					else
					{
						choose.setEnabled(true);
						deny.setEnabled(true);
					}
    			}
    			catch(Exception ve)
    			{
    				ve.printStackTrace();
    			}
    			}
				
				
			}
			
		}
		list.addListSelectionListener(new ListListener());
		
		choose=new JButton("选择");
		choose.addActionListener(this);
		deny=new JButton("拒绝");
		deny.addActionListener(this);
		close=new JButton("关闭");
		close.addActionListener(this);
		
		studentf=new ShowStudent(motherp);
		studentf.unmodifiable();
		
		Box box1=Box.createHorizontalBox();
		JLabel title=new JLabel("请选择你的研究生");
		box1.add(title);
		
		Box box2=Box.createHorizontalBox();
		JPanel b=new JPanel();
		b.setLayout(new FlowLayout());
		b.add(listPane);
		
		JPanel a=new JPanel();
		a.setLayout(new FlowLayout());
    	a.add(studentf);
    	
    	box2.add(b);
    	box2.add(a);
    	
    	Box box3=Box.createHorizontalBox();
    	box3.add(choose);
    	box3.add(deny);
    	box3.add(close);
    	
    	Box box=Box.createVerticalBox();
    	box.add(box1);
    	box.createVerticalStrut(20);
    	box.add(box2);
    	box.add(box3);
    	
    	cp.add(box);
    	
    	try
		{
			student=teacher.getT_student();
			ListIterator studentIterator=student.listIterator();
			
			try
			{
				Items.removeAllElements();
			}
			catch(Exception he)
			{}
			
			while(studentIterator.hasNext())
			{
				Items.add(0,(studentIterator.next()));
			}
			if(student.size()==0)
			{
				Items.add(0," DEFAULT");
				Font font=new Font(null,Font.BOLD,15);
				title.setFont(font);
				title.setText("目前没有学生选你");
				try
				{
					list.setSelectedIndex(0);
				}
				catch(Exception dd)
				{}
			}
			else if(student.size()!=0)
			{
				
				list.setSelectedIndex(0);
				studentf.setStudent((String)(student.getLast()));
			}
		
		}
		catch(Exception ee)
		{
			ee.printStackTrace();
		}
       	this.setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
    	if(e.getSource()==close)
    	{
    		this.dispose();
    	}
    	else if(e.getSource()==choose)
    	{
    		Object[]options={"是","取消"};
    		int j=
    			JOptionPane.showOptionDialog(this,"确定选择这个学生","确定选择",
					JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null,
							options,null);
    		if(j==0)
    		{
    		String ID=(String)list.getSelectedValue();
    		try
			{
				FileInputStream input1=new FileInputStream(sfile);
				ObjectInputStream input2=new ObjectInputStream(input1);
				ConcreteStudentManager manger=
					(ConcreteStudentManager)input2.readObject();
				input1.close();
				input2.close();
				GraStudent s=(GraStudent)manger.IDsearchStudent(ID);
				s.teacher_answer(2);
				teacher.select();
				
				FileOutputStream one=new FileOutputStream(sfile);
				ObjectOutputStream two=new ObjectOutputStream(one);
				two.writeObject(manger);
				one.close();
				two.close();
				studentf.setStudent(ID);
    		}
    		catch(Exception ve)
    		{
    			ve.printStackTrace();
    		}
    		choose.setEnabled(false);
    		deny.setEnabled(false);
    		}
    		else if(j==1)
    		{}
    	}
    	else if(e.getSource()==deny)
    	{
    		Object[]options={"是","取消"};
    		int j=
    		JOptionPane.showOptionDialog(this,"确定选择这个导师","确定选择",
				JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null,
						options,null);
    		if(j==0)
    		{
    		String ID=(String)list.getSelectedValue();
    		try
			{
				FileInputStream input1=new FileInputStream(sfile);
				ObjectInputStream input2=new ObjectInputStream(input1);
				ConcreteStudentManager manger=
					(ConcreteStudentManager)input2.readObject();
				input1.close();
				input2.close();
				GraStudent s=(GraStudent)manger.IDsearchStudent(ID);
				s.teacher_answer(3);
				
				FileOutputStream one=new FileOutputStream(sfile);
				ObjectOutputStream two=new ObjectOutputStream(one);
				two.writeObject(manger);
				one.close();
				two.close();
				studentf.setStudent(ID);
    		}
    		catch(Exception ve)
    		{
    			ve.printStackTrace();
    		}
    		choose.setEnabled(false);
    		deny.setEnabled(false);
    		}
    		else if(j==0)
    		{}
    	}
    }
}

⌨️ 快捷键说明

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