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

📄 login.java~39~

📁 一个看上去不错的JAVA毕业设计作品
💻 JAVA~39~
字号:
package zcgl;

import java.awt.*;

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Login extends JFrame {
    Connection con = null;
    Statement smt = null;
    ResultSet rs = null;
    public Login() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jLabel1.setText("用户名");
        jLabel1.setBounds(new Rectangle(97, 90, 82, 40));
        jButton1.setBounds(new Rectangle(110, 211, 112, 37));
        jButton1.setText("登陆");
        jButton1.addActionListener(new Login_jButton1_actionAdapter(this));
        txtPass.setBounds(new Rectangle(162, 154, 133, 22));
        jButton2.setBounds(new Rectangle(232, 212, 112, 37));
        jButton2.setText("退出");
        jButton2.addActionListener(new Login_jButton2_actionAdapter(this));
        jLabel2.setText("密码");
        jLabel2.setBounds(new Rectangle(99, 149, 51, 30));
        this.getContentPane().add(txtPass);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.getContentPane().add(jLabel1);
        this.getContentPane().add(txtName);
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(jButton2);
        this.getContentPane().add(jButton1);
        txtName.setBounds(new Rectangle(162, 98, 131, 27));
    }

    JLabel jLabel1 = new JLabel();
    JTextField txtName = new JTextField();
    JLabel jLabel2 = new JLabel();
    JButton jButton1 = new JButton();
    JPasswordField txtPass = new JPasswordField();
    JButton jButton2 = new JButton();
    public void jButton1_actionPerformed(ActionEvent e) {
        con = new DbCon().getConnection();
        try {
            smt = con.createStatement();
            rs = smt.executeQuery("select * from OPERATOR");
            if (rs.next()) {
                String name = rs.getString(1).trim();
                String pass = rs.getString(2).trim();
                if (txtName.getText().equals(name) &&
                    String.copyValueOf(txtPass.getPassword()).equals(pass)) {
                    MainFrame frame = new MainFrame();
                    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);

                } else {
                    JOptionPane.showMessageDialog(this, "用户名或密码错误!");
                    return;
                }
            }
        } catch (SQLException ex) {
        }

    }

    public void jButton2_actionPerformed(ActionEvent e) {
       dispose();
    }
}


class Login_jButton2_actionAdapter implements ActionListener {
    private Login adaptee;
    Login_jButton2_actionAdapter(Login adaptee) {
        this.adaptee = adaptee;
    }

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


class Login_jButton1_actionAdapter implements ActionListener {
    private Login adaptee;
    Login_jButton1_actionAdapter(Login adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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