资源预览内容
第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
亲,该文档总共7页全部预览完了,如果喜欢就下载吧!
资源描述
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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号