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

📄 loginjdialog.java

📁 一个图书管理系统
💻 JAVA
字号:
package com.UI;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import com.DAO.UserDAO;
import com.exception.DataBaseException;
import com.VO.UserVO;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class LoginJDialog extends javax.swing.JDialog {
	private JButton ButtonEnter;
	private JTextField userName;
	private JPasswordField userPwd;
	private JLabel LabTitle;
	private JLabel LabPwd;
	private JLabel LabNmae;
	private JButton ButtonExit;
//	IconImage icon=new IconImage();

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		LoginJDialog inst = new LoginJDialog(frame);
		inst.setVisible(true);
	}
	
	public LoginJDialog(JFrame frame) {
		super(frame);
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				setSize(350, 250);
				this.addWindowListener(new WindowAdapter(){
					public void windowClosing(WindowEvent e){
						System.exit(0);	
					}
				});
				this.setResizable(false);
				Toolkit tool=Toolkit.getDefaultToolkit();
				Dimension dim=tool.getScreenSize();
				this.setLocation((int)(dim.width-350)/2,(int)(dim.height-250)/2);
			//	getContentPane().setBackground(new java.awt.Color(192,192,192));
			//	getContentPane().setBackground(new java.awt.Color(10,230,20));

				{
					ButtonExit = new JButton();
					ButtonExit.addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e) {
							System.exit(0);							
						}
						
					});
					getContentPane().add(ButtonExit);
					ButtonExit.setText("\u9000 \u51fa");
					ButtonExit.setBounds(203, 175, 98, 28);
					ButtonExit.setFont(new java.awt.Font("宋体",1,12));
//					ButtonExit.setIcon(new ImageIcon(getClass().getClassLoader().getResource("com/sixgroup/Image/2222.ico")));
				//	ButtonExit.setBackground(new java.awt.Color(64,0,128));
				}
				{
					ButtonEnter = new JButton();
					ButtonEnter.addActionListener(new EnterListener());
					getContentPane().add(ButtonEnter);
					ButtonEnter.setText("\u8fdb \u5165");
					ButtonEnter.setBounds(63, 175, 98, 28);
					ButtonEnter.setFont(new java.awt.Font("宋体",1,12));
				//	ButtonEnter.setBackground(new java.awt.Color(128,128,192));
				//	ButtonEnter.setIcon(new ImageIcon(getClass().getClassLoader().getResource("com/sixgroup/image/mima.ico")));
					ButtonEnter.setBorder(BorderFactory.createCompoundBorder(
						null,
						null));
				}
				{
					LabNmae = new JLabel();
					getContentPane().add(LabNmae);
					LabNmae.setText("\u7528\u6237\u540d:");
					LabNmae.setBounds(63, 84, 56, 28);
					LabNmae.setFont(new java.awt.Font("宋体",0,16));
				}
				{
					LabPwd = new JLabel();
					getContentPane().add(LabPwd);
					LabPwd.setText("\u5bc6  \u7801:");
					LabPwd.setBounds(63, 126, 56, 28);
					LabPwd.setFont(new java.awt.Font("宋体",0,16));
				}
				{
					LabTitle = new JLabel();
					getContentPane().add(LabTitle);
					LabTitle.setText(" \u4e66 \u5e97 \u7ba1 \u7406 \u7cfb \u7edf");
					LabTitle.setBounds(77, 21, 210, 28);
					LabTitle.setFont(new java.awt.Font("华文彩云",0,26));
					LabTitle.setForeground(new java.awt.Color(0,0,255));
				}
				{
					userName = new JTextField();
					getContentPane().add(userName);
					userName.setBounds(147, 84, 147, 28);
					userName.setFont(new java.awt.Font("Tahoma",0,14));
					userName.setText("admin");
				}
				{
					userPwd = new JPasswordField();
					getContentPane().add(userPwd);
					userPwd.setBounds(147, 126, 147, 28);
					userPwd.setFont(new java.awt.Font("Tahoma",0,14));
					userPwd.setText("admin");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private class EnterListener implements ActionListener{
		public void actionPerformed(ActionEvent e) {
			String name=userName.getText().trim();
			String password=new String(userPwd.getPassword());
			UserVO user1=new UserVO();
			user1.setUserName(name);
			user1.setUserPwd(password);
			UserDAO user=new UserDAO();
			try {
				if (user.find(user1)!=null){
					MainJFrame mainpro=new MainJFrame();
				//	mainpro.setVisible(true);
				//	dispose();
					setVisible(false);
				}else{
					JOptionPane.showMessageDialog(null,"用户名或密码错误,请重新输入!");
				}
			} catch (HeadlessException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			} catch (DataBaseException e1) {
				// TODO 自动生成 catch 块
				JOptionPane.showMessageDialog(null,e1.getState());
			}
		}
		
	}

}

⌨️ 快捷键说明

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