logindialog.java

来自「一个网吧管理系统程序」· Java 代码 · 共 163 行

JAVA
163
字号
package bar;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class loginDialog extends JDialog {  JPanel panel1 = new JPanel();  JLabel jLabel1 = new JLabel();  JTextField jTextField1 = new JTextField();  JLabel jLabel2 = new JLabel();  JButton jButton1 = new JButton();  JButton jButton2 = new JButton();  JLabel jLabel3 = new JLabel();  JPasswordField jPasswordField1 = new JPasswordField();  BorderLayout borderLayout1 = new BorderLayout();  public loginDialog(mainFrame frame, String title, boolean modal) {    super(frame, title, modal);    Frame1 = frame;    this.setLocation(250,200);    try {      jbInit();      pack();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  public loginDialog() {    this(null, "", false);  }  private void jbInit() throws Exception {    panel1.setLayout(null);    this.getContentPane().setLayout(borderLayout1);    panel1.setPreferredSize(new Dimension(300, 200));    panel1.setRequestFocusEnabled(true);    jLabel3.setFont(new java.awt.Font("Serif", 1, 16));    jLabel3.setForeground(Color.blue);    jLabel3.setHorizontalAlignment(SwingConstants.CENTER);    jLabel3.setText("欢迎查询,请输卡号、密码");    jLabel3.setBounds(new Rectangle(0, 10, 300, 30));    jLabel1.setFont(new java.awt.Font("Serif", 1, 13));    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);    jLabel1.setText("卡号:");    jLabel1.setBounds(new Rectangle(80, 60, 45, 25));    jTextField1.setText("88888888");    jTextField1.setBounds(new Rectangle(125, 60, 95, 25));    jLabel2.setFont(new java.awt.Font("Serif", 1, 13));    jLabel2.setText("密码:");    jLabel2.setBounds(new Rectangle(80, 110, 45, 25));    jPasswordField1.setText("88888888");    jPasswordField1.setBounds(new Rectangle(125, 110, 95, 25));    jButton1.setBounds(new Rectangle(75, 150, 60, 25));    jButton1.setText("确定");    jButton1.addActionListener(new loginDialog_jButton1_actionAdapter(this));    jButton2.setBounds(new Rectangle(165, 150, 60, 25));    jButton2.setText("重置");    jButton2.addActionListener(new loginDialog_jButton2_actionAdapter(this));    getContentPane().add(panel1, BorderLayout.CENTER);    panel1.add(jLabel2, null);    panel1.add(jLabel3, null);    panel1.add(jPasswordField1, null);    panel1.add(jTextField1, null);    panel1.add(jLabel1, null);    panel1.add(jButton1, null);    panel1.add(jButton2, null);    con = barConnect.getconn();  }  void jButton2_actionPerformed(ActionEvent e) {    jTextField1.setText("");    jPasswordField1.setText("");  }  void jButton1_actionPerformed(ActionEvent e) {    try{      if(jTextField1.getText().trim()!= null){        stmt = con.createStatement();        String loginQuery =  "";        String passwordtemp = "";        for(int i=0;i<jPasswordField1.getPassword().length;i++)        {          passwordtemp += jPasswordField1.getPassword()[i];        }        loginQuery = "select * from Card where CardID = " +                                    Integer.parseInt(jTextField1.getText().trim()) +                                    " and password = "+passwordtemp;        ResultSet rs = stmt.executeQuery(loginQuery);        if (rs.next()) {          Frame1.login_true();          Frame1.SetCardID(Integer.parseInt(jTextField1.getText().trim()));          rs.close();          con.close();          this.hide();          return;        }        else{          Frame1.login_false();          jTextField1.setText("卡号或者密码错误。");        }      }    }    catch(SQLException ex){      System.out.print("系统或者输进数据错误!"+ex.toString());    }  }  protected void processWindowEvent(WindowEvent e) {   super.processWindowEvent(e);   if (e.getID() == WindowEvent.WINDOW_CLOSING) {     Frame1.login_false();     this.hide();   } }  private Connection con;  private mainFrame Frame1;  private Statement stmt;}class loginDialog_jButton2_actionAdapter implements java.awt.event.ActionListener {  loginDialog adaptee;  loginDialog_jButton2_actionAdapter(loginDialog adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton2_actionPerformed(e);  }}class loginDialog_jButton1_actionAdapter implements java.awt.event.ActionListener {  loginDialog adaptee;  loginDialog_jButton1_actionAdapter(loginDialog adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton1_actionPerformed(e);  }}

⌨️ 快捷键说明

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