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

📄 systementerframe.java~211~

📁 用java 写的学生信息管理系统
💻 JAVA~211~
字号:
package prjsystementer;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.Font;
import java.util.Date;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JScrollPane;
import java.sql.ResultSet;
import java.sql.*;
import javax.swing.JOptionPane;
import java.awt.SystemColor;
import java.awt.Color;
import java.util.*;
import prjTeacher.Teacher;
import prjTeacher.TeacherModal;


public class SystemEnterFrame extends JFrame {

    public SystemEnterFrame() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    // System.out.println();

    private void jbInit() throws Exception {
        //ImageIcon i=new ImageIcon("F:/城市夜景.jpg");
        // null.setIcon(i);

        Date d = new Date();
        getContentPane().setLayout(null);
        lblName.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
        lblName.setText("用户名");
        lblName.setBounds(new Rectangle(50, 62, 58, 50));
        btnCancel.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
        btnOk.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
        lblPass.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
        btnOk.setBackground(Color.orange);
        btnOk.setBounds(new Rectangle(89, 219, 106, 31));
        btnOk.setText("登陆");
        btnOk.addActionListener(new SystemEnterFrame_btnOk_actionAdapter(this));
        btnCancel.setBackground(Color.orange);
        btnCancel.setBounds(new Rectangle(228, 219, 106, 31));
        btnCancel.setText("关闭");
        btnCancel.addActionListener(new
                                    SystemEnterFrame_btnCancel_actionAdapter(this));
        txtPass.setBackground(SystemColor.text);
        txtPass.setBounds(new Rectangle(120, 144, 248, 31));
        txtName.setBackground(SystemColor.text);
        txtName.setCaretColor(Color.darkGray);
        txtName.setBounds(new Rectangle(120, 70, 248, 33));
        txtName.addActionListener(new SystemEnterFrame_txtName_actionAdapter(this));
        this.getContentPane().setBackground(Color.orange);
        this.setForeground(Color.black);
        this.setIconImage(null);
        this.setTitle("橘黄软件");
        jLabel1.setBackground(Color.yellow);
        jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 20));
        jLabel1.setText("系统登陆");
        jLabel1.setBounds(new Rectangle(159, 11, 119, 39));
        jScrollPane1.getViewport().setBackground(Color.orange);
        jScrollPane1.setBounds(new Rectangle(21, 55, 374, 139));
        this.getContentPane().add(btnCancel);
        this.getContentPane().add(jLabel1);
        this.getContentPane().add(lblName);
        this.getContentPane().add(txtName);
        this.getContentPane().add(txtPass);
        this.getContentPane().add(btnOk);
        this.getContentPane().add(lblPass);
        this.getContentPane().add(jScrollPane1);
        lblPass.setText("密码");
        lblPass.setBounds(new Rectangle(52, 132, 64, 49));
    }


    public static void main(String[] args) {
        SystemEnterFrame systementerframe = new SystemEnterFrame();
        systementerframe.setSize(423, 295);
        //显示弹出窗口的位置,现在在显示屏的中间=
        systementerframe.setLocation(300, 150);
        systementerframe.setDefaultCloseOperation(systementerframe.
                                                  EXIT_ON_CLOSE);
        systementerframe.setVisible(true);

    }


    JLabel lblName = new JLabel();
    JLabel lblPass = new JLabel();
    JTextField txtName = new JTextField();
    JPasswordField txtPass = new JPasswordField();
    JButton btnCancel = new JButton();
    JButton btnOk = new JButton();
    JLabel jLabel1 = new JLabel();
    JScrollPane jScrollPane1 = new JScrollPane();
    private Object username;
    public void btnCancel_actionPerformed(ActionEvent e) {
        this.dispose();
    }


    public void btnOk_actionPerformed(ActionEvent e) {
        DBManager db = new DBManager();
        String name = this.txtName.getText();
        String pass = new String(this.txtPass.getPassword());
        //String pass = String.valueOf(txtPass.getPassword());
        String sql = "select * from T_USERINFO where userName='" + name +
                     "' and pwd='" + pass + "'";
        ResultSet rs = db.ExecuteQuery(sql);
        if (name.equals("")) {
            JOptionPane.showMessageDialog(this, "请输入用户名和密码");
            return;
        }

        try {
            if (rs.next() == false) {
                JOptionPane.showMessageDialog(this, "用户名或密码错误");
                this.txtName.setText("");
                this.txtPass.setText("");
                return;
            }
            String DBname = rs.getString("userName");
            String DBpass = rs.getString("pwd");
            if (name.equals(DBname) == false || pass.equals(DBpass) == false) {
                JOptionPane.showMessageDialog(this, "用户名或密码错误");
                this.txtName.setText("");
                this.txtPass.setText("");
                return;
            }
            //"当前登录用户:" +
            MainFrame f = new MainFrame(name);
            f.setExtendedState(JFrame.MAXIMIZED_BOTH);
            //  f.setSize(600, 500);
            //显示弹出窗口的位置,现在在显示屏的中间
            //  f.setLocation(300, 150);
            f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
            f.setVisible(true);
            this.dispose();

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public void txtName_actionPerformed(ActionEvent e) {

    }
}


class SystemEnterFrame_txtName_actionAdapter implements ActionListener {
    private SystemEnterFrame adaptee;
    SystemEnterFrame_txtName_actionAdapter(SystemEnterFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class SystemEnterFrame_btnOk_actionAdapter implements ActionListener {
    private SystemEnterFrame adaptee;
    SystemEnterFrame_btnOk_actionAdapter(SystemEnterFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class SystemEnterFrame_btnCancel_actionAdapter implements ActionListener {
    private SystemEnterFrame adaptee;
    SystemEnterFrame_btnCancel_actionAdapter(SystemEnterFrame adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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