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

📄 main.java

📁 基于javaSwing的图书馆信息管理系统 使用oracle数据库连接
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.lib;

import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.sql.Connection;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.lib.db.oper.Login;
import com.lib.gui.BookManage;
import com.lib.gui.BorrowerManage;
import com.lib.gui.PublisherManage;

public class Main extends JFrame {	
	
	private static BookManage bookManage;

	private static BorrowerManage borrowerManage;
	
	private static PublisherManage publisherManage;	

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel_book = null;

	private JLabel jLabel_login = null;

	private JPanel jPanel_login = null;

	private JLabel jLabel_pwd = null;

	private JLabel jLabel_usr = null;

	private JButton jButton = null;

	private JButton jButton1 = null;

	private JTextField jTextField = null;

	private JPasswordField jPasswordField = null;

	private Connection con = null;

	private char[] pwd = null;

	private String usr = null;

	private JLabel jLabel_exit = null;

	private OpenBorrowerFrameListener borrowerListener;
	
	private OpenPublisherFrameListener publisherListener;

	private LoginListener loginListener;

	private LogoffListener logoffListener;

	private JLabel jLabel_borrower = null;

	private JLabel jLabel_publisher = null;

	/**
	 * This method initializes jPanel_login
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel_login() {
		if (jPanel_login == null) {
			jLabel_usr = new JLabel();
			jLabel_usr.setBounds(new java.awt.Rectangle(15, 60, 91, 31));
			jLabel_usr.setIcon(new ImageIcon(
					"E:/img/standard_037_32.png"));
			jLabel_usr.setText("密码");
			jLabel_pwd = new JLabel();
			jLabel_pwd.setBounds(new java.awt.Rectangle(15, 15, 91, 31));
			jLabel_pwd.setIcon(new ImageIcon(
					"E:/img/standard_143_32.png"));
			jLabel_pwd.setText("用户名");
			jPanel_login = new JPanel();
			jPanel_login.setLayout(null);
			jPanel_login.setBounds(new java.awt.Rectangle(240, 60, 256, 151));
			jPanel_login.add(jLabel_pwd, null);
			jPanel_login.add(jLabel_usr, null);
			jPanel_login.add(getJButton(), null);
			jPanel_login.add(getJButton1(), null);
			jPanel_login.add(getJTextField(), null);
			jPanel_login.add(getJPasswordField(), null);
			jPanel_login.setVisible(false);
		}
		return jPanel_login;
	}

	/**
	 * This method initializes jButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new java.awt.Rectangle(15, 105, 106, 30));
			jButton.setIcon(new ImageIcon(
					"E:/img/standard_030_20.png"));
			jButton
					.setHorizontalTextPosition(javax.swing.SwingConstants.TRAILING);			
			jButton.setText("确定");
		}
		jButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				usr = jTextField.getText().trim();				
				String tmppwd = jPasswordField.getText();
				System.out.println(usr);

				
				if (usr.length() == 0) {
					JOptionPane.showMessageDialog(Main.this, "请输入用户名", "错误",
							JOptionPane.INFORMATION_MESSAGE);
				} else if (tmppwd.length() == 0) {
					JOptionPane.showMessageDialog(Main.this, "请输入密码", "错误",
							JOptionPane.INFORMATION_MESSAGE);
				} else if ((con = DBConnection.getConnection()) == null) {
					JOptionPane.showMessageDialog(Main.this,
							"数据库连接失败,请检查数据库系统", "连接不成功",
							JOptionPane.INFORMATION_MESSAGE);
				} else if (tmppwd.equals(Login.getPwd(usr))) {
					jPanel_login.setVisible(false);
					jTextField.setText(null);
					jPasswordField.setText(null);
					
					if(Login.FLAG == 'A') {
						JOptionPane.showMessageDialog(Main.this, "管理员登录成功", "登录",JOptionPane.INFORMATION_MESSAGE);
						jLabel_book.setIcon(new ImageIcon("E:/img/standard_014_128.png"));
						jLabel_book.setToolTipText(" 图书信息维护");
						jLabel_login.setToolTipText("管理员注销");
						
						Login.FLAG = 'a';
						
						
						jLabel_borrower.setVisible(true);					
						jLabel_publisher.setVisible(true);					
						if (publisherListener == null) {
							publisherListener = new OpenPublisherFrameListener();
						}					
						jLabel_publisher.addMouseListener(publisherListener);	
						if (borrowerListener == null) {
							borrowerListener = new OpenBorrowerFrameListener();
						}
						jLabel_borrower.addMouseListener(borrowerListener);
					
					}else if(Login.FLAG == 'B') {
						JOptionPane.showMessageDialog(Main.this, "用户登录成功", "登录",JOptionPane.INFORMATION_MESSAGE);
						jLabel_book.setIcon(new ImageIcon("E:/img/standard_156_128.png"));
						jLabel_book.setToolTipText("图书信息");
						jLabel_login.setToolTipText("用户注销");
						
						Login.FLAG = 'b';
					}
					

					
					jLabel_login.removeMouseListener(loginListener);					
					jLabel_login.setIcon(new ImageIcon("E:/img/standard_030_128.png"));
					logoffListener = new LogoffListener();
					jLabel_login.addMouseListener(logoffListener);

					jLabel_exit.setIcon(new ImageIcon(
							"E:/img/xi/Icons/png/power.png"));
					
					jLabel.setIcon(new ImageIcon("E:/img/BG/5.jpg"));
					
					
					
				} else {
					JOptionPane.showMessageDialog(Main.this, "用户名或密码错误,请重新输入",
							"错误", JOptionPane.INFORMATION_MESSAGE);
				}
			}
		});
		return jButton;
	}

	/**
	 * This method initializes jButton1
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new java.awt.Rectangle(135, 105, 106, 30));
			jButton1.setIcon(new ImageIcon(
					"E:/img/standard_109_20.png"));			
			jButton1.setText("取消");
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jPanel_login.setVisible(false);
				}
			});
		}
		return jButton1;
	}

	/**
	 * This method initializes jTextField
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new java.awt.Rectangle(120, 15, 121, 31));
		}
		return jTextField;
	}

	/**
	 * This method initializes jPasswordField
	 * 
	 * @return javax.swing.JPasswordField
	 */
	private JPasswordField getJPasswordField() {
		if (jPasswordField == null) {
			jPasswordField = new JPasswordField();
			jPasswordField.setBounds(new java.awt.Rectangle(120, 60, 121, 31));
		}
		return jPasswordField;
	}

	/**
	 * This is the default constructor
	 */
	public Main() {
		super();
		initialize();
	}
	
	public static void main(String[] args) {

⌨️ 快捷键说明

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