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

📄 login.java

📁 一个学籍管理系统。
💻 JAVA
字号:
/*
 * Created on 2004-5-30
 */
/**
 * @author Zhou Qi
 */
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.tree.*;



public class Login extends JInternalFrame
{
  
	private JLabel 
	lbID=new JLabel("UserName:"),
	lbPassword=new JLabel("Password:");
	
	private JTextField tfID=new JTextField(15);
	private JPasswordField pfPassword=new JPasswordField(15);
	private RadioButtons rbChoice;
	private JButton btnSubmit=new JButton("Submit");
	private JButton btnReset=new JButton("Reset");
	static final String ERRORMSG= "Access Denied! \nPossible Reason:ID or Password Wrong!   \nAdvise:Abort or Retry";
	private ActionListener alSubmit=new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
		    
			String id=tfID.getText();
			String password=pfPassword.getText();
			int _choice=rbChoice.getSelectType();
			if(id.equals("")||password.equals(""))
			{
				String empty="UserName and Password fields must be filled!";
				JOptionPane.showMessageDialog(null,empty,"Invalid Input",JOptionPane.OK_OPTION);
			}
			Identify myidentify=new Identify(_choice,id,password);
			if(myidentify.check())
			{
				
			}
			else
			{
				error();			
			}
				
		}
		
	};
	private ActionListener alReset=new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			pfPassword.setText("");
			tfID.setText("");		
		}
	};
	public void error()
	{
		JOptionPane.showMessageDialog(this, ERRORMSG,"Error",JOptionPane.OK_OPTION);
	}
	public Login(int i)
	{
		this.setTitle("Login");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
		rbChoice=new RadioButtons(i);
		lbID.setSize(12,5);
		lbID.setIcon(new ImageIcon("Image/username.gif"));
		lbPassword.setSize(12,5);
		lbPassword.setIcon(new ImageIcon("Image/password.gif"));
		btnReset.setSize(10,5);
		btnSubmit.setSize(10,5);
		btnSubmit.addActionListener(alSubmit);
		btnReset.addActionListener(alReset);
		Container cp=this.getContentPane();
		cp.setLayout(new FlowLayout());
		cp.add(lbID);
		cp.add(tfID);
		cp.add(lbPassword);
		//rbChoice.init();
		cp.add(pfPassword);
		cp.add(rbChoice);
		cp.add(btnSubmit);
		cp.add(btnReset);
		//super("LogIn", true, true, true, true);
		setSize( 325, 180);
		setLocation( 75, 75);
	}
}
class RadioButtons extends JApplet
{
	private int _item;
	
	private ButtonGroup g=new ButtonGroup();
	private int select;
	private JRadioButton
	rb1=new JRadioButton("Student",false),
	rb2=new JRadioButton("Teacher",false),
	rb3=new JRadioButton("Administrator",false);
	
	private ActionListener al=new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			String name=((JRadioButton)e.getSource()).getText();
			if(name.equals(rb3.getText()))				
				select=3;
			else if(name.equals(rb2.getText()))
			   select=2;
			else
			   select=1;	
		}
	};
	public int getSelectType()
	{	
		return select;
	}
	public void testConnection()
	{
		
	}
	public RadioButtons(int i)
	{
		rb1.setSize(5,5);
		rb2.setSize(5,5);
		rb3.setSize(5,5);
	
		rb1.addActionListener(al);
		rb2.addActionListener(al);
		rb3.addActionListener(al);
		g.add(rb1);
		g.add(rb2);
		g.add(rb3);
		Container cp=this.getContentPane();
		cp.setLayout(new FlowLayout());
		cp.add(rb1);
		cp.add(rb2);
		cp.add(rb3);
		switch(i)
		{
			case 1:rb1.setSelected(true);
			break;
			case 2:rb2.setSelected(true);
			break;
			case 3:rb3.setSelected(true);
			break;
			default:rb1.setSelected(true);
		}
			
	}
		
}

⌨️ 快捷键说明

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