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

📄 studymanager.java

📁 自己编的学籍管理系统
💻 JAVA
字号:
package myprojects.studymanager;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class StudyManager extends JFrame implements ActionListener
{
	JButton button1,button2;
	JRadioButton jbutton1,jbutton2,jbutton3;
	ButtonGroup buttongroup;
	JTextField text;
	JPasswordField code;
	File file;
	File tfile;
	CardLayout card;
	JPanel p,q;
	ShowStudent showStudent;
	ShowTeacher showTeacher;
	ShowAdmin showAdmin;

	String t1,t3;
	char[] t2;
	Container cp;

	public StudyManager()
	{
		super("学籍管理系统");
		cp=this.getContentPane();
		file=new File(".\\data\\Student.study");
		tfile=new File(".\\data\\Teacher.study");
		
		
		Box box1=Box.createHorizontalBox();
		box1.add(new JLabel("学号/工号:"));
		text=new JTextField(10);
		box1.add(text);
		Box box2=Box.createHorizontalBox();
		box2.add(new JLabel("密码:       "));
		code=new JPasswordField(10);
		code.setEchoChar('*');
		box2.add(code);
		
		button1=new JButton("确定");
		button2=new JButton("清空");
		button1.addActionListener(this);
		button2.addActionListener(this);
		Box box3=Box.createHorizontalBox();
		box3.add(button1);
		box3.add(button2);

		jbutton1=new JRadioButton("Student",true);
		jbutton2=new JRadioButton("Teacher");
		jbutton3=new JRadioButton("Administrator");
		buttongroup=new ButtonGroup();
		buttongroup.add(jbutton1);
		buttongroup.add(jbutton2);
		buttongroup.add(jbutton3);
		
		Box box4=Box.createHorizontalBox();
		box4.add(jbutton1);
		box4.add(jbutton2);
		box4.add(jbutton3);
		
		Box box5=Box.createHorizontalBox();
		JLabel label=new JLabel("欢迎进入学籍管理系统");
		box5.add(label);
		Font font=new Font(null,Font.BOLD,18);
		label.setFont(font);
		
		Box box=Box.createVerticalBox();
		box.add(Box.createVerticalStrut(40));
		box.add(box5);
		box.add(Box.createVerticalStrut(25));
		box.add(box1);
		box.add(box2);
		box.add(Box.createVerticalStrut(10));
		box.add(box3);
		box.add(Box.createVerticalStrut(10));
		box.add(box4);
		box.add(Box.createVerticalStrut(10));
		
		
		p=new JPanel();
		q=new JPanel();
		p.setLayout(new FlowLayout());
		p.add(box);
		
		card=new CardLayout();
		q.setLayout(card);
		q.add("login",p);
		
		showStudent=new ShowStudent(this);
		q.add("showStudent",showStudent);
		
		showTeacher=new ShowTeacher(this);
		q.add("showTeacher",showTeacher);
		
		cp.add(q);
			
		this.addWindowListener(new WindowAdapter()
				{
					public void windowClosing(WindowEvent e)
					{
						System.exit(0);
					}
				});
		this.setSize(400,350);
		this.setVisible(true);
			
	}
	public void setCardlogin()
	{
		t1="";
		for(int i=0;i<=t2.length-1;i++)
			t2[i]=0;
		code.setText("");
		card.show(q,"login");
		
	}

		
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==button2){
			text.setText("");
			code.setText("");
		}
		if(e.getSource()==button1){
			t2=code.getPassword();
			t3=new String(t2);
			if(text.getText().equals(""))
				JOptionPane.showMessageDialog(this,
					"Imput the ID!","Warning",JOptionPane.ERROR_MESSAGE);
			else if(code.getPassword().equals(""))
				JOptionPane.showMessageDialog(this,
					"Imput the code!","Warning",JOptionPane.ERROR_MESSAGE);
			else 
			{
				t1=text.getText();
				
				if(jbutton1.isSelected())
				{
					try
					{
					
					FileInputStream input1=new FileInputStream(file);
					ObjectInputStream input2=new ObjectInputStream(input1);
					ConcreteStudentManager manger=
						(ConcreteStudentManager)input2.readObject();
					input1.close();
					input2.close();
					AbstractStudent s=manger.IDsearchStudent(t1);
					if(s.codeCheck(t3))
					{
						
						card.show(q,"showStudent");
						showStudent.setStudent(t1);
					}
					else
						JOptionPane.showMessageDialog(this,
							"Wrong code!","Warning",JOptionPane.ERROR_MESSAGE);
						
					}
					
					catch(StudentNotFoundException fe)
					{
						JOptionPane.showMessageDialog(this,
							"Student not found!","Warning",JOptionPane.ERROR_MESSAGE);
					}
					catch(Exception ee)
					{
						ee.printStackTrace();
					}	
				
				}
				
				else if(jbutton2.isSelected())
				{
					try
					{
						
						FileInputStream input3=new FileInputStream(tfile);
						ObjectInputStream input4=new ObjectInputStream(input3);
						LinkedList teacherlist=
							(LinkedList)input4.readObject();
						input3.close();
						input4.close();
						ListIterator tea=teacherlist.listIterator();
						boolean found=false;
						Teacher teacher=new Teacher();
						while(tea.hasNext())
						{
							Teacher next=(Teacher)tea.next();
							if(next.getT_ID().equals(t1))
							{
								found=true;
								teacher=next;
								break;
							}
						}
						if(found==false)
							JOptionPane.showMessageDialog(this,
								"Teacher Not Found!","Warning",JOptionPane.ERROR_MESSAGE);
						else
						{
							if(teacher.codeCheck(t3))
							{
								card.show(q,"showTeacher");
								showTeacher.setTeacher(t1);
								
							}
							else
								JOptionPane.showMessageDialog(this,
									"Wrong code!","Warning",JOptionPane.ERROR_MESSAGE);
							
						}
					}
					catch(Exception txe)
					{
						txe.printStackTrace();
					}
					
				}
				
				else if(jbutton3.isSelected())
				{
					

					if(t1.equals("admin")&&t2.equals("1"))
					{
						showAdmin=new ShowAdmin(this);
						code.setText("");
					}
					else if(!(t1.equals("admin")))
						JOptionPane.showMessageDialog(this,
									"Wrong ID!","Warning",JOptionPane.ERROR_MESSAGE);
					else if(!(t2.equals("1")))
						JOptionPane.showMessageDialog(this,
									"Wrong code!","Warning",JOptionPane.ERROR_MESSAGE);
				}
				
				
			}
		}
	}
	public static void main(String[] args)
	{
		new StudyManager();
	}
}
	

⌨️ 快捷键说明

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