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

📄 loginframe1.java

📁 图书管理系统源代码,05年某人写的,还算不错
💻 JAVA
字号:
package booksboeeowreadsystem;

import java.awt.*;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.sql.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.WindowStateListener;
import java.awt.event.WindowFocusListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;

/**
 * <p>Title: 图书借阅系统</p>
 *
 * <p>Description: 科学的管理系统</p>
 *
 * <p>Copyright: 吴明卫小组</p>
 *
 * <p>Company: </p>
 *
 * @author 吴明卫
 * @version 1.0
 */
public class LoginFrame1 extends JFrame {
        Dbcom db;
        ImageIcon login = new ImageIcon("../booksboeeowreadsystem/image/login.png");
        public static boolean oK;
        public static boolean dangqian;
        JLabel jLabel1 = new JLabel();
        JLabel jLabel2 = new JLabel();
        JTextField jtName = new JTextField();
        JPasswordField jPassword = new JPasswordField();
        JLabel jLabel3 = new JLabel();
        JButton jButton1 = new JButton();
        JButton jButton2 = new JButton();
        JLabel jButton3 = new JLabel(login);
    public LoginFrame1(Dbcom db) {
        try {
              this.db=db;
              LoginFrame1.oK = false;
              jbInit();
          } catch (Exception exception) {
              exception.printStackTrace();
          }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        this.setEnabled(true);
        this.setResizable(false);
        this.setTitle("管理员登录界面");
        this.addComponentListener(new LoginFrame1_this_componentAdapter(this));
        this.addWindowStateListener(new LoginFrame1_this_windowStateAdapter(this));
        jLabel1.setFont(new java.awt.Font("Default", Font.PLAIN, 16));
        jLabel1.setForeground(Color.blue);
        jLabel1.setToolTipText("");
        jLabel1.setText("密    码:");
        jLabel1.setBounds(new Rectangle(48, 119, 72, 34));
        jtName.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
        jtName.setForeground(Color.blue);
        jtName.setBounds(new Rectangle(130, 72, 168, 28));
        jPassword.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
        jPassword.setForeground(Color.magenta);
        jPassword.setBounds(new Rectangle(130, 122, 168, 28));
        jPassword.addKeyListener(new LoginFrame1_jPassword_keyAdapter(this));
        jLabel3.setFont(new java.awt.Font("Default", Font.BOLD, 32));
        jLabel3.setForeground(Color.magenta);

        jLabel3.setText("管 理 员 登 录");
        jLabel3.setBounds(new Rectangle(28, 19, 230, 31));
        jButton1.setBounds(new Rectangle(238, 178, 61, 31));
        jButton1.setFont(new java.awt.Font("Default", Font.PLAIN, 16));
        jButton1.setForeground(Color.blue);
        jButton1.setMargin(new Insets(2, 2, 2, 2));
        jButton1.setText("重置");
        jButton1.addActionListener(new LoginFrame1_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(44, 178, 61, 31));
        jButton2.setFont(new java.awt.Font("Default", Font.PLAIN, 16));
        jButton2.setForeground(Color.blue);
        jButton2.setMargin(new Insets(2, 2, 2, 2));
        jButton2.setText("登录");
        jButton2.addActionListener(new LoginFrame1_jButton2_actionAdapter(this));
        jButton3.setBackground(SystemColor.control);
        jButton3.setBounds(new Rectangle(277, 13, 47, 39));
        jButton3.setBorder(null);
        jButton3.setDisabledIcon(login);
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(jLabel1);
        this.getContentPane().add(jtName);
        this.getContentPane().add(jPassword);
        this.getContentPane().add(jButton3);
        this.getContentPane().add(jLabel3);
        this.getContentPane().add(jButton2);
        this.getContentPane().add(jButton1);
        jLabel2.setFont(new java.awt.Font("Default", Font.PLAIN, 16));
        jLabel2.setForeground(Color.blue);
        jLabel2.setToolTipText("");
        jLabel2.setText("用户名:");
        jLabel2.setBounds(new Rectangle(48, 69, 71, 34));
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        //增加数据库的联系
        String name = jtName.getText().trim();
        String pass = new String(jPassword.getPassword()).trim();
        if (name.length() > 0 && pass.length() > 0) {
            String sql = "select quanxian,zhuangtai from quanxian where name='" + name +
                         "' and password='" + pass + "'";
            //判断登录的密码和用户信息,成功登录如下
            db.search(sql);
            try {
                if (db.rs.next()) {
                    if(db.rs.getBoolean(2)){
                        //在数据库中获得权限的整型值
                        SystemFrame1.t = db.rs.getInt(1);
                        //JOptionPane.showMessageDialog(this, "登录成功", "成功",JOptionPane.QUESTION_MESSAGE);
                        SystemFrame1.login = name;
                        LoginFrame1.oK = true;
                        LoginFrame1.dangqian = false;
                        this.dispose();
                    }
                    else
                        JOptionPane.showMessageDialog(this, "此用户没有登陆权限,已被禁用!!\n 请咨询管理员", "警告",
                                JOptionPane.WARNING_MESSAGE);
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "登录失败,\n请确认 登录名 和密码",
                                                  "失败",
                                                  JOptionPane.ERROR_MESSAGE);
                }
            } catch (SQLException ex) {
                System.out.println(ex.toString() + "\n登录时出现异常");
            }
            db.myClose(1);
        }
        else
            JOptionPane.showMessageDialog(this,"资料没有填写完整,\n请丛重新填写完整","警告",JOptionPane.WARNING_MESSAGE);
    }



    public void jButton1_actionPerformed(ActionEvent e) {
        jtName.setText("");
        jPassword.setText("");
    }

    public void jPassword_keyTyped(KeyEvent e) {
      /*
        JOptionPane.showMessageDialog(null,""+e.equals("\n"));
       if(e.getKeyChar()=='\n')
       {

           if(jtName.getText().trim().length()<1){
               jtName.setFocusable(true);
               JOptionPane.showMessageDialog(this, "用户名不能为空,请填写", "错误",JOptionPane.ERROR_MESSAGE);
           }
           else if(jPassword.getPassword().toString().trim().length()<1 || jPassword.getPassword().toString().trim().indexOf("[c@")<=1){
               JOptionPane.showMessageDialog(this, "密码不能为空,请填写", "错误",JOptionPane.ERROR_MESSAGE);
               jPassword.setFocusable(true);
           }
           else
           {
               String name = jtName.getText().trim();
               String pass = new String(jPassword.getPassword()).trim();
               String sql = "select quanxian from quanxian where name='" + name +
                            "' and password='" + pass + "'";
               //判断登录的密码和用户信息,成功登录如下
               db.search(sql);
               try {
                   if (db.rs.next()) {

                       //在数据库中获得权限的整型值
                       SystemFrame1.t = db.rs.getInt(1);
                       JOptionPane.showMessageDialog(this, "登录成功", "成功",
                               JOptionPane.QUESTION_MESSAGE);
                       this.dispose();
                   } else {
                       SystemFrame1.t = 0;
                       JOptionPane.showMessageDialog(this, "登录失败,\n请确认 登录名 和密码",
                               "失败",
                               JOptionPane.ERROR_MESSAGE);
                   }
               } catch (SQLException ex) {
                   System.out.println(ex.toString() + "\n登录时出现异常");
               }
           }
       }

    }
      */
    }


    public void this_windowStateChanged(WindowEvent e) {
        this.setState(NORMAL);

    }

    public void jButton4_actionPerformed(ActionEvent e) {
        LoginFrame1.dangqian = false;
         this.dispose();
    }


    public void this_componentHidden(ComponentEvent e) {
      //  JOptionPane.showMessageDialog(null,"界面隐藏");
        LoginFrame1.dangqian = false;
    //     this.dispose();
    }


}


class LoginFrame1_jButton1_actionAdapter implements ActionListener {
    private LoginFrame1 adaptee;
    LoginFrame1_jButton1_actionAdapter(LoginFrame1 adaptee) {
        this.adaptee = adaptee;
    }

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




class LoginFrame1_this_windowStateAdapter implements WindowStateListener {
    private LoginFrame1 adaptee;
    LoginFrame1_this_windowStateAdapter(LoginFrame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void windowStateChanged(WindowEvent e) {
        adaptee.this_windowStateChanged(e);
    }
}





class LoginFrame1_this_componentAdapter extends ComponentAdapter {
    private LoginFrame1 adaptee;
    LoginFrame1_this_componentAdapter(LoginFrame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void componentHidden(ComponentEvent e) {
        adaptee.this_componentHidden(e);
    }
}


class LoginFrame1_jButton2_actionAdapter implements ActionListener {
    private LoginFrame1 adaptee;
    LoginFrame1_jButton2_actionAdapter(LoginFrame1 adaptee) {
        this.adaptee = adaptee;
    }

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


class LoginFrame1_jPassword_keyAdapter extends KeyAdapter {
    private LoginFrame1 adaptee;
    LoginFrame1_jPassword_keyAdapter(LoginFrame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void keyTyped(KeyEvent e) {
        adaptee.jPassword_keyTyped(e);
    }
}

⌨️ 快捷键说明

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