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

📄 login.java

📁 java语言编写的基于sql2000开发的图书馆管理系统
💻 JAVA
字号:
package main;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JComboBox;
import java.awt.Font;
import java.sql.ResultSet;
import main.StartClass;
import purchase.Purchase;
import depot.Depot;

import main.DataBase;
import reception.Reception;

public class LogIn extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JButton confirm = null;

	private JButton cancel = null;

	private JTextField username = null;

	private JPasswordField passWord = null;

	private JComboBox type = null;

	/**
	 * This method initializes confirm	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getConfirm() {
		if (confirm == null) {
			confirm = new JButton();
			confirm.setBounds(new Rectangle(40, 174, 102, 47));
			confirm.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
			confirm.setText("确认");
			confirm.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					//System.out.println("hi");
					String username=LogIn.this.getUsername().getText();
					String password=new String(LogIn.this.getPassWord().getPassword());
					String type=(String)LogIn.this.getType().getSelectedItem();
					//System.out.println(username+" "+password+" "+type);
					String sql;
					String table;
					if(type.equals("会员")){
						table="member";
					}else{
						table="staff";
					}
					sql="select * from " 
							+table+" where ID_Number='"+username+
							"'"+" and password='"+password+"'";
					String job=" and job='"+type+"'";
					if(!type.equals("会员"))
						sql+=job;
					System.out.println(sql);
					ResultSet result=DataBase.executeQuery(sql);
					if(DataBase.exist(result)){
						//System.out.println("there exists");
						StartClass.username=username;
						StartClass.password=password;
						StartClass.type=type;
						LogIn.this.logIn(type);
					}else{
						//System.out.println("there not exists");
						javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
								"用户信息错误!!!!");
						
					}		
					}
			});
		}
		return confirm;
	}

	/**
	 * This method initializes cancel	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getCancel() {
		if (cancel == null) {
			cancel = new JButton();
			cancel.setBounds(new Rectangle(157, 174, 102, 47));
			cancel.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
			cancel.setText("取消");
			cancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					//System.out.println("hhi");
					System.exit(0);
				}
			});
		}
		return cancel;
	}

	/**
	 * This method initializes username	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getUsername() {
		if (username == null) {
			username = new JTextField();
			username.setBounds(new Rectangle(101, 37, 162, 29));
		}
		return username;
	}

	/**
	 * This method initializes passWord	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getPassWord() {
		if (passWord == null) {
			passWord = new JPasswordField();
			passWord.setBounds(new Rectangle(102, 70, 162, 29));
		}
		return passWord;
	}

	/**
	 * This method initializes type	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getType() {
		if (type == null) {
			type = new JComboBox();
			type.setBounds(new Rectangle(103, 105, 160, 25));
			type.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
			type.addItem("会员");
			type.addItem("借阅台");
			type.addItem("仓库");
			type.addItem("采购");
			//type.addItem("馆长");
		}
		return type;
	}

	/**
	 * This is the default constructor
	 */
	public LogIn() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(293, 287);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setContentPane(getJContentPane());
		this.setTitle("登陆对话框");
		this.setVisible(true);
		this.setLocation(250,250);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(24, 106, 65, 27));
			jLabel2.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
			jLabel2.setText("身份");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(24, 71, 65, 27));
			jLabel1.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
			jLabel1.setText("密码");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(24, 37, 65, 27));
			jLabel.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
			jLabel.setText("用户名");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(getConfirm(), null);
			jContentPane.add(getCancel(), null);
			jContentPane.add(getUsername(), null);
			jContentPane.add(getPassWord(), null);
			jContentPane.add(getType(), null);
		}
		return jContentPane;
	}
	
	private void logIn(String type){
		this.dispose();
		if(type.equals("采购")){
			//System.out.println("caigou");
			new Purchase();
		}else if(type.equals("仓库")){
			new Depot();
		}else if(type.equals("馆长")){
			
		}else if(type.equals("借阅台")){
			new Reception();
		}else{
			new member.Member();
		}
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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