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

📄 logindialog.java~1~

📁 JBuilder2006设计的服装进销存管理系统。 只是一个Demo,但帮助文档等一应俱全。 在使用前请先将数据库中的内容加载到SQLServer2000中
💻 JAVA~1~
字号:
package com.lzw.login;

import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;

import javax.swing.*;

import com.lzw.MainFrame;
import com.lzw.dao.Dao;

public class LoginDialog extends JFrame {
	private static final long serialVersionUID = 1L;

	private LoginPanel loginPanel = null;

	private JLabel jLabel = null;

	private JTextField userField = null;

	private JLabel jLabel1 = null;

	private JPasswordField passwordField = null;

	private JButton loginButton = null;

	private JButton exitButton = null;

	private static String userStr;

	private MainFrame mainFrame;

	/**
	 * @param owner
	 */
	public LoginDialog() {
		try {
			UIManager.setLookAndFeel(UIManager
					.getSystemLookAndFeelClassName());
			mainFrame = new MainFrame();
			initialize();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 初始化loginPanel登录面板的方法
	 * 
	 * @return com.lzw.login.LoginPanel
	 */
	private LoginPanel getLoginPanel() {
		if (loginPanel == null) {
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(86, 71, 55, 18));
			jLabel1.setText("密 码:");
			jLabel = new JLabel();
			jLabel.setText("用户名:");
			jLabel.setBounds(new Rectangle(85, 41, 56, 18));
			loginPanel = new LoginPanel();
			loginPanel.setLayout(null);
			loginPanel.setBackground(new Color(0xD8DDC7));
			loginPanel.add(jLabel, null);
			loginPanel.add(getUserField(), null);
			loginPanel.add(jLabel1, null);
			loginPanel.add(getPasswordField(), null);
			loginPanel.add(getLoginButton(), null);
			loginPanel.add(getExitButton(), null);
		}
		return loginPanel;
	}

	/**
	 * This method initializes userField
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getUserField() {
		if (userField == null) {
			userField = new JTextField();
			userField.setBounds(new Rectangle(142, 39, 127, 22));
		}
		return userField;
	}

	/**
	 * This method initializes passwordField
	 * 
	 * @return javax.swing.JPasswordField
	 */
	private JPasswordField getPasswordField() {
		if (passwordField == null) {
			passwordField = new JPasswordField();
			passwordField.setBounds(new Rectangle(143, 69, 125, 22));
			passwordField.addKeyListener(new java.awt.event.KeyAdapter() {
				public void keyTyped(java.awt.event.KeyEvent e) {
					if(e.getKeyChar()=='\n')
						loginButton.doClick();
				}
			});
		}
		return passwordField;
	}

	/**
	 * This method initializes loginButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getLoginButton() {
		if (loginButton == null) {
			loginButton = new JButton();
			loginButton.setBounds(new Rectangle(109, 114, 48, 20));
			loginButton.setIcon(new ImageIcon(getClass().getResource(
					"/res/loginButton.jpg")));
			loginButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						userStr = userField.getText();
						String passStr = new String(passwordField.getPassword());
						if (!Dao.checkLogin(userStr, passStr)) {
							JOptionPane.showMessageDialog(LoginDialog.this,
									"用户名与密码无法登录", "登录失败",
									JOptionPane.ERROR_MESSAGE);
							return;
						}
					} catch (Exception e1) {
						e1.printStackTrace();
					}
					mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					mainFrame.setVisible(true);
					mainFrame.getCzyStateLabel().setText(userStr);
					setVisible(false);
				}
			});
		}
		return loginButton;
	}

	/**
	 * This method initializes exitButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getExitButton() {
		if (exitButton == null) {
			exitButton = new JButton();
			exitButton.setBounds(new Rectangle(181, 114, 48, 20));
			exitButton.setIcon(new ImageIcon(getClass().getResource(
					"/res/exitButton.jpg")));
			exitButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.exit(0);
				}
			});
		}
		return exitButton;
	}

	/**
	 * 界面初始化方法
	 * 
	 * @return void
	 */
	private void initialize() {
		Dimension size = getToolkit().getScreenSize();
		setLocation((size.width - 296) / 2, (size.height - 188) / 2);
		setSize(296, 188);
		this.setTitle("系统登录");
		setContentPane(getLoginPanel());
	}

	public String getUserStr() {
		return userStr;
	}

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

⌨️ 快捷键说明

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