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

📄 loginframe.java

📁 酒店管理系统后台数据库存储过程
💻 JAVA
字号:
package rummery;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import entity.Manager;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import entity.DBOperatorBean;
import java.sql.ResultSet;
import java.sql.*;
import java.awt.Font;

/**
 * <p>Title: Hawaii rummery manage</p>
 *
 * <p>Description: minityperummery manage</p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: Yue.</p>
 *
 * @author not attributable
 * @version 1.0
 */
public class LoginFrame extends JFrame {
    public LoginFrame() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        lblIcon.setText("");
        lblIcon.setBorder(BorderFactory.createEtchedBorder());
        lblIcon.setIcon(icon);
        lblIcon.setBounds(new Rectangle(35, 29, 329, 200));
        txtName.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        txtName.setText("");
        txtName.setBounds(new Rectangle(191, 284, 130, 30));
        lblName.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        lblName.setText("用户");
        lblName.setBounds(new Rectangle(81, 284, 90, 30));
        lblPwd.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        lblPwd.setToolTipText("");
        lblPwd.setText("密码");
        lblPwd.setBounds(new Rectangle(81, 320, 90, 30));
        btnLogin.setBackground(UIManager.getColor(
                "InternalFrame.activeTitleGradient"));
        btnLogin.setBounds(new Rectangle(90, 365, 90, 30));
        btnLogin.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        btnLogin.setText("");
        btnLogin.addActionListener(new LoginFrame_btnLogin_actionAdapter(this));
        btnExit.setBackground(UIManager.getColor(
                "InternalFrame.activeTitleGradient"));
        btnExit.setBounds(new Rectangle(206, 365, 90, 30));
        btnExit.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        btnExit.setText("");
        btnExit.addActionListener(new LoginFrame_btnExit_actionAdapter(this));
        txtPwd.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        txtPwd.setText("");
        txtPwd.setBounds(new Rectangle(191, 319, 130, 30));
        txtPwd.addActionListener(new LoginFrame_txtPwd_actionAdapter(this));
        this.getContentPane().setBackground(Color.white);
        this.setForeground(Color.white);
        this.setResizable(false);
        this.setTitle("用户登录");
        cboAdmin.setBackground(new Color(255, 255, 210));
        cboAdmin.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        cboAdmin.setToolTipText("");
        cboAdmin.setBounds(new Rectangle(192, 248, 130, 30));

        cboAdmin.addItem("客房管理员");
        cboAdmin.addItem("经营管理员");
        cboAdmin.addItem("系统管理员");

        lblAdminType.setFont(new java.awt.Font("DialogInput", Font.PLAIN, 15));
        lblAdminType.setToolTipText("");
        lblAdminType.setText("选择管理员");
        lblAdminType.setBounds(new Rectangle(81, 248, 90, 30));

//         ImageIcon admin = new ImageIcon("image\\login\\lAdmin.jpg");
//         ImageIcon username = new ImageIcon("image\\login\\lUsername.jpg");
//         ImageIcon  password = new ImageIcon("image\\login\\lPassword.jpg");
//         this.lblAdminType.setIcon(admin);
//         this.lblName.setIcon(username);
//         this.lblPwd.setIcon(password);


         this.btnExit.setIcon( new ImageIcon("image\\login\\exit.jpg"));
         this.btnLogin.setIcon(new ImageIcon("image\\login\\login.jpg"));
        this.getContentPane().add(lblIcon);
        this.getContentPane().add(btnLogin);
        this.getContentPane().add(btnExit);
        this.getContentPane().add(cboAdmin);
        this.getContentPane().add(lblAdminType);
        this.getContentPane().add(lblName);
        this.getContentPane().add(lblPwd);
        this.getContentPane().add(txtName);
        this.getContentPane().add(txtPwd);
        dbo = new DBOperatorBean();
    }

    JLabel lblIcon = new JLabel();
    JTextField txtName = new JTextField();
    JLabel lblName = new JLabel();
    JLabel lblPwd = new JLabel();
    JButton btnLogin = new JButton();
    JButton btnExit = new JButton();
    JPasswordField txtPwd = new JPasswordField();
    Icon icon = new ImageIcon("image\\Autumn.jpg");
    boolean packFrame = false;
    public static String manager;
    JComboBox cboAdmin = new JComboBox();
    JLabel lblAdminType = new JLabel();
    DBOperatorBean dbo;
    ResultSet rs = null;

    public void btnLogin_actionPerformed(ActionEvent e) {
      if(this.txtName.getText().equals("")||this.txtPwd.getText().equals(""))
      {
       JOptionPane.showMessageDialog(this,"用户名与密码不能为空!!","提示",JOptionPane.INFORMATION_MESSAGE);
        this.txtName.setText("");
        this.txtPwd.setText("");
        this.txtName.requestFocus();
       return ;
       }

      int index = this.cboAdmin.getSelectedIndex();
        if (index == 2) {

            this.manager = this.cboAdmin.getSelectedItem().toString();
            System.out.println(this.manager);
        }
        if (index == 1) {

            this.manager = this.cboAdmin.getSelectedItem().toString();
            System.out.println(this.manager);
        }
        if (index == 0) {
            this.manager = this.cboAdmin.getSelectedItem().toString();
            System.out.println(this.manager);
        }

        Manager manager = new Manager();
        manager.setName(txtName.getText());
        manager.setPassword(txtPwd.getText());



            try {
                String sql = "select * from admin where name = '" +
                         this.txtName.getText() + "'and password = '"
                         + this.txtPwd.getText() + "' and remark = '" +
                         this.cboAdmin.getSelectedItem().toString() + "'";
                 rs = dbo.returnQuery(sql);
                if (!rs.next()) {
                     JOptionPane.showMessageDialog(this,"用户名或密码错误!!登陆失败!!\n 请输入正确的信息,从新登陆!!","提示",JOptionPane.INFORMATION_MESSAGE);
                     this.txtName.setText("");
                     this.txtPwd.setText("");
                     this.txtName.requestFocus();
                     return;
                }
                else
                {
                    JOptionPane.showMessageDialog(this,
                                         "欢迎" + manager.getName() + "登陆成功!!",
                                          "登陆", JOptionPane.INFORMATION_MESSAGE);
                 showMainfrm();
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
            }





    }

    public void btnExit_actionPerformed(ActionEvent e) {
        this.dispose();
    }

    public void showMainfrm() {
        MainFrame frame = new MainFrame();
        frame.setBounds(200, 200, 700, 550);
        frame.setVisible(true);
//        // Validate frames that have preset sizes
//        // Pack frames that have useful preferred size info, e.g. from their layout
//        if (packFrame) {
//            frame.pack();
//        } else {
//            frame.validate();
//        }
//
//        // Center the window
//        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//        Dimension frameSize = frame.getSize();
//        if (frameSize.height > screenSize.height) {
//            frameSize.height = screenSize.height;
//        }
//        if (frameSize.width > screenSize.width) {
//            frameSize.width = screenSize.width;
//        }
//        frame.setLocation((screenSize.width - frameSize.width) / 2,
//                          (screenSize.height - frameSize.height) / 2);
//        frame.setVisible(true);

        this.dispose();
    }

    public void txtPwd_actionPerformed(ActionEvent e) {
        btnLogin_actionPerformed(e);
    }


}


class LoginFrame_txtPwd_actionAdapter implements ActionListener {
    private LoginFrame adaptee;
    LoginFrame_txtPwd_actionAdapter(LoginFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.txtPwd_actionPerformed(e);
    }
}


class LoginFrame_btnExit_actionAdapter implements ActionListener {
    private LoginFrame adaptee;
    LoginFrame_btnExit_actionAdapter(LoginFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnExit_actionPerformed(e);
    }
}


class LoginFrame_btnLogin_actionAdapter implements ActionListener {
    private LoginFrame adaptee;
    LoginFrame_btnLogin_actionAdapter(LoginFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnLogin_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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