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

📄 login.java~35~

📁 出租车管理系统,为本人毕业设计. 还请大家多多指教了
💻 JAVA~35~
字号:
package car;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
import java.awt.*;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;
import javax.swing.border.BevelBorder;
import javax.swing.border.MatteBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import car.DataBaseManager;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;

public class Login extends Frame{ //implements ActionListener  {
    DataBaseManager db=new DataBaseManager();
    ResultSet s;
    public Login() {
        try {
            jbInit();
            addWindowListener(new WindowAdapter()
                                {
                                        public void windowClosing(WindowEvent e)
                                        {
                                                System.exit(0);
                                        }
                                });

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

    public static void main(String[] args) {
        Login login = new Login();
    }

    private void jbInit() throws Exception {
        setLocation(200,100);
        setSize(416,320);
        this.setLayout(xYLayout1);
        jPanel1.setBackground(Color.white);
        jPanel1.setBorder(border8);
        jPanel1.setDebugGraphicsOptions(DebugGraphics.LOG_OPTION);
        jPanel1.setLayout(xYLayout2);
        this.setVisible(true);
        this.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        this.setResizable(true);
        this.setTitle("登陆窗口");
        xYLayout1.setWidth(415);
        xYLayout1.setHeight(285);
        jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        jLabel1.setForeground(new Color(85, 92, 164));
        jLabel1.setBorder(border5);
        jLabel1.setText("  用户类型:");
        jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        jLabel2.setForeground(new Color(85, 92, 164));
        jLabel2.setBorder(border6);
        jLabel2.setToolTipText("");
        jLabel2.setText("      I   D:");
        jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        jLabel3.setForeground(new Color(85, 92, 164));
        jLabel3.setBorder(border7);
        jLabel3.setIcon(null);
        jLabel3.setText("  密       码:");
        idtext.setForeground(new Color(85, 92, 164));
        idtext.setText("");
        passwordtext.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        passwordtext.setForeground(new Color(85, 92, 164));
        passwordtext.setText("");
        jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        jButton1.setForeground(new Color(85, 92, 164));
        jButton1.setText("登录");
        jButton1.addActionListener(new Login_jButton1_actionAdapter(this));
        jButton2.setBackground(Color.white);
        jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        jButton2.setForeground(new Color(85, 92, 164));
        jButton2.addActionListener(new Login_jButton2_actionAdapter(this));
        jComboBox1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
        jComboBox1.setForeground(new Color(85, 92, 164));
        jComboBox1.addItem("管理员");
        jComboBox1.addItem("驾驶员");
        jLabel4.setBackground(Color.white);
        jLabel4.setText("");
        this.add(jPanel1, new XYConstraints(2, 2, 168, 282));
        jPanel1.add(jLabel4, new XYConstraints(0, 0, 165, 279));
        this.add(jComboBox1, new XYConstraints(283, 19, 109, 37));
        this.add(idtext, new XYConstraints(283, 77, 109, 38));
        this.add(passwordtext, new XYConstraints(283, 139, 109, 40));
        this.add(jLabel1, new XYConstraints(183, 19, 87, 37));
        this.add(jLabel2, new XYConstraints(183, 77, 87, 38));
        this.add(jLabel3, new XYConstraints(183, 139, 87, 40));
        this.add(jButton1, new XYConstraints(183, 208, 100, 54));
        this.add(jButton2, new XYConstraints(294, 208, 98, 54));
        addWindowListener(new WindowAdapter() {
            public void WindowClosing(WindowEvent e) {
                String q = "谢谢您的使用,确定要退出吗?";
                              int ok = JOptionPane.showConfirmDialog(null, q, "确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
                              if (ok == JOptionPane.YES_OPTION) {
                                  dispose();
                                  System.exit(0);
                      }
            }
        });

    }

    JPanel jPanel1 = new JPanel();
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.white, new Color(148, 145, 140));
    Border border2 = BorderFactory.createLineBorder(Color.white, 2);
    Border border3 = BorderFactory.createBevelBorder(BevelBorder.RAISED,
            Color.white, Color.white, new Color(103, 101, 98),
            new Color(148, 145, 140));
    Border border4 = new MatteBorder(null);
    Border border5 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.white, new Color(148, 145, 140));
    JLabel jLabel2 = new JLabel();
    Border border6 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.white, new Color(148, 145, 140));
    JLabel jLabel3 = new JLabel();
    Border border7 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.white, new Color(148, 145, 140));
    JComboBox jComboBox1 = new JComboBox();
    JTextField idtext = new JTextField();
    JPasswordField passwordtext = new JPasswordField();
    JButton jButton1 = new JButton(new ImageIcon("\\image\\pic.gif") );
    JButton jButton2 = new JButton(new ImageIcon("\\image\\closed2.gif"));
    Border border8 = BorderFactory.createEtchedBorder(Color.white,
            new Color(148, 145, 140));
    JLabel jLabel4 = new JLabel(new ImageIcon("\\image\\200611632555781.gif"));
    XYLayout xYLayout2 = new XYLayout();
    public void jButton2_actionPerformed(ActionEvent e) {
        String q = "谢谢您的使用,确定要退出吗?";
                              int ok = JOptionPane.showConfirmDialog(null, q, "确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
                              if (ok == JOptionPane.YES_OPTION) {
                                  dispose();
                                  System.exit(0);
                      }
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        String strSQL;
        String str;
        String str2;
        strSQL="";
        str="";
        str2="";
        if (idtext.getText().equals("") || passwordtext.getPassword().equals("")) {
            String warning = "用户名或密码不能为空!";
            JOptionPane.showMessageDialog(null, "warning", "警告",
                                          JOptionPane.ERROR_MESSAGE);
            return;
        } else {
            if (jComboBox1.getSelectedItem() == "管理员") {
                strSQL = "select * from admin where ID='" + idtext.getText().trim() +
                         "'";
                str = "管理员";
                str2="密码";
            } else if (jComboBox1.getSelectedItem() == "驾驶员") {
                strSQL = "select * from driver where 驾驶证号='" +
                         idtext.getText().trim() + "'";
                str = "  "+idtext.getText().trim();
                str2="身份证号";
            }

            s = db.getResult(strSQL);
            try {
                if (s.first()) {

                    String ss = new String(passwordtext.getPassword());
                  //  System.out.print(passwordtext.getPassword());

                    if (ss.equals(s.getString(str2))) {
                        new MainWindow(str);
                        this.dispose();
                        db.closeConnection();
                    } else {
                        JOptionPane.showMessageDialog(this, "密码错误,请重新输入!", "警告",
                                JOptionPane.WARNING_MESSAGE);
                        passwordtext.setText("");
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "用户名错误,请重新输入!", "警告",
                                                  JOptionPane.WARNING_MESSAGE);
                    idtext.setText("");
                    passwordtext.setText("");
                    idtext.requestFocus();

                }
            } catch (HeadlessException ex) {
            } catch (SQLException ex) {
            }

            try {
                if (!db.getResult(strSQL).first()) {
                    JOptionPane.showMessageDialog(null, "该用户名不存在!");
                    idtext.setText("");
                    passwordtext.setText("");
                    idtext.requestFocus();
                }
            } catch (HeadlessException ex1) {
            } catch (SQLException ex1) {
            }
        }
    }
}

    // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //    addWindowListener(new WindowAdapter(){
       //         public void WindowClosing(WindowEvent e){
         //               System.exit(0);}
         //       });




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);
    }
}


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);
    }
}

⌨️ 快捷键说明

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