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

📄 loginframe.java~77~

📁 我从网上下的,好像还行,和大家分享一下,
💻 JAVA~77~
字号:
package atm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class LoginFrame
    extends JFrame {
  /**
   * 计数器用于计算用户输入错误的次数
   */
  int y=0;
  int n = 0;
  //存储用户信息
  static String ID = null;
  static String passWord = null;
  static int money = 0;

  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JPasswordField jPasswordField1 = new JPasswordField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JLabel jLabel4 = new JLabel(new ImageIcon("Image\\blue.jpg"));
  JLabel jLabel3 = new JLabel();
  JLabel jLabel5 = new JLabel(new ImageIcon("Image\\password.png"));
  JLabel jLabel6 = new JLabel();
  /**
   * 构造器方法
   */
  public LoginFrame() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * 初始化用户登录界面
   * @throws java.lang.Exception
   */
  private void jbInit() throws Exception {
    this.setUndecorated(true);
    this.setSize(new Dimension(416, 281));
    this.setState(Frame.NORMAL);
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setForeground(Color.white);
    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel1.setText("卡号");
    jLabel1.setBounds(new Rectangle(43, 94, 55, 32));
    this.getContentPane().setLayout(null);
    jLabel2.setBounds(new Rectangle(41, 143, 55, 32));
    jLabel2.setText("密码");
    jLabel2.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel2.setForeground(Color.white);
    jTextField1.setBackground(Color.white);
    jTextField1.setEnabled(true);
    jTextField1.setForeground(Color.white);
    jTextField1.setOpaque(false);
    jTextField1.setToolTipText("请输入您的银行帐号");
    jTextField1.setCaretColor(Color.cyan);
    jTextField1.setSelectedTextColor(Color.yellow);
    jTextField1.setSelectionStart(11);
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(97, 94, 241, 30));
    jPasswordField1.setBackground(Color.lightGray);
    jPasswordField1.setForeground(Color.white);
    jPasswordField1.setOpaque(false);
    jPasswordField1.setToolTipText("请输入您的银行密码");
    jPasswordField1.setCaretColor(Color.cyan);
    jPasswordField1.setSelectedTextColor(Color.yellow);
    jPasswordField1.setText("");
    jPasswordField1.setBounds(new Rectangle(97, 144, 241, 30));
    jPasswordField1.addKeyListener(new LoginFrame_jPasswordField1_keyAdapter(this));
    jButton1.setBackground(Color.white);
    jButton1.setBounds(new Rectangle(69, 211, 91, 26));
    jButton1.setFont(new java.awt.Font("Dialog", 0, 14));
    jButton1.setToolTipText("登录操作");
    jButton1.setText("登录");
    jButton1.addActionListener(new LoginFrame_jButton1_actionAdapter(this));
    jButton2.setText("退出");
    jButton2.addActionListener(new LoginFrame_jButton2_actionAdapter(this));
    jButton2.setFont(new java.awt.Font("Dialog", 0, 14));
    jButton2.setToolTipText("推出系统");
    jButton2.setBackground(Color.white);
    jButton2.setBounds(new Rectangle(254, 211, 91, 26));
    this.setEnabled(true);
    this.setResizable(false);
    this.setTitle("ATM机登录");
    jLabel4.setBounds(new Rectangle(-4, 0, 479, 304));
    jLabel3.setFont(new java.awt.Font("Dialog", 1, 24));
    jLabel3.setForeground(Color.white);
    jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel3.setText("S B  银 行 交 易 系 统");
    jLabel3.setBounds(new Rectangle(61, 11, 277, 57));
    jLabel5.setPreferredSize(new Dimension( -1, -1));
    jLabel5.setToolTipText("服务 QQ:625001993");
    jLabel5.setBounds(new Rectangle(343, 141, 42, 37));
    jLabel6.setFont(new java.awt.Font("Dialog", 0, 14));
    jLabel6.setForeground(Color.white);
    jLabel6.setText("系统设置");
    jLabel6.setBounds(new Rectangle(341, 247, 69, 22));
    jLabel6.addKeyListener(new LoginFrame_jLabel6_keyAdapter(this));
    this.getContentPane().add(jLabel3, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton2, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jPasswordField1, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jLabel5, null);
    this.getContentPane().add(jLabel6, null);
    this.getContentPane().add(jLabel4, null);
  }

  void jButton1_actionPerformed(ActionEvent e) {
    /**
     * 判断是否已经错误输入3次,如果是则推出系统
     */
    if (n == 3) {
      JOptionPane.showMessageDialog(this,
          "对不起,您输入错误信息超过规定3次,系统将关闭,\n请与我行联系,QQ:625001993", "系统提示", 1);
      System.exit(0);
    }
    /**
     * 获得用户输入的信息
     */
    ID = this.jTextField1.getText().trim();
    passWord = this.jPasswordField1.getText().trim();
    /**
     * 实例化数据库操作类,用于对数据库的操作
     */
    Database bean = new Database();
    /**
     * 打开数据库连接
     */
    try {
      bean.OpenConn();
    }
    catch (Exception ex) {
      System.out.println("登录时连接数据库出错");
    }
    /**
     * 构建从表中查询输入的用户名和密码的记录的SQL语句
     */
    String sql = "select * from userInfo where ID='" + ID + "'and passWord='" +
        passWord + "'and isEnable=0";
    String sql2= "select * from userInfo where ID='" + ID + "'and passWord='" +
        passWord + "'";
    ResultSet rs=bean.executeQuery(sql);
    ResultSet rs2 = bean.executeQuery(sql2);
    /**
     * 定义判断正确输入的布尔值
     */
    boolean isRight = false;
    try {
      if (rs.next()) {
        ID = rs.getString("ID").trim();
        passWord = rs.getString("passWord").trim();
        money = rs.getInt("money");
        isRight = true;
      }
      else if (rs2.next()) {
        JOptionPane.showMessageDialog(this,
                                      "对不起,您的帐户已经冻结,请与我行联系!\n联系QQ:625001993",
                                      "系统提示", 1);
        this.jPasswordField1.setText("");
        return;
      }
      else {
        JOptionPane.showMessageDialog(this, "对不请您输入的帐号和密码不符,请重新输入", "系统提示", 1);
      }
    }
    catch (Exception ex) {
      System.out.println("登录时读取数据出错");
    }
    //关闭数据库连接
    bean.closeStmt();
    bean.closeConn();

    if (isRight) {
      this.hide();
      JFrame open = new MainFrame();
      try {
        Thread.sleep(800);
      }
      catch (Exception ex) {
        System.out.println("线程中断");
      }
      /**
       * centre the Frame
       */
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension frameSize = open.getSize();
      if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
      }
      if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
      }
      open.setLocation( (screenSize.width - frameSize.width) / 2,
                       (screenSize.height - frameSize.height) / 2);

      open.show();
    }
    else {
      n++;
      this.jPasswordField1.setText("");
    }
  }

  void jButton2_actionPerformed(ActionEvent e) {
    int value = JOptionPane.showConfirmDialog(this, "你确认要推出ATM系统吗?", "系统提示", 0,
                                              1);
    if (value == 0) {
      System.exit(0);
    }
    else {
      return;
    }
  }

  void jPasswordField1_keyReleased(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
      jButton1_actionPerformed(new ActionEvent(jButton2, 0, null));
    }
  }

  void jLabel6_keyReleased(KeyEvent e) {
    if (y == 3) {
    JOptionPane.showMessageDialog(this,
                                  "错误操作过多,系统将关闭,若有问题请与管理员联系\n QQ:625001993",
                                  "错误", 1);
    System.exit(0);
  }
  //调出管理员信息,正确时调出增加用户对话框
  JPasswordField pwd = new JPasswordField();
  Object[] message = {
      "请输入管理员密码:", pwd};
  int res = JOptionPane.showConfirmDialog(this, message, "",
                                          JOptionPane.OK_CANCEL_OPTION,
                                          JOptionPane.QUESTION_MESSAGE);
  String passWord = pwd.getText();

  if (res == JOptionPane.CANCEL_OPTION) {
    return;
  }

  Database bean = new Database();
  try {
    bean.OpenConn();
  }
  catch (Exception ex) {
    System.out.println("ex:at login admin");
  }

    /**
     * 构建查询管理员的密码的SQL语句
     */
    String sql = "select * from admin where admin.passWord='" + passWord + "'";
    ResultSet rs = bean.executeQuery(sql);
    try {
      if (rs.next()) {
        y = 0;
         JOptionPane.showMessageDialog(this,"下面的操作是设置要登录的服务器端","",1);
         String ip=JOptionPane.showInputDialog(this,"","",1).trim();
        if(ip==null){
          return;
        }

      }
      else {
        JOptionPane.showMessageDialog(this, "登录系统失败,管理员密码有误!", "错误", 1);
        y++;
        return;
      }
    }
    catch (Exception ex) {
      System.out.println("ex:at select admin's msg");
    }
  }
}

class LoginFrame_jButton1_actionAdapter
    implements java.awt.event.ActionListener {
  LoginFrame adaptee;

  LoginFrame_jButton1_actionAdapter(LoginFrame adaptee) {
    this.adaptee = adaptee;
  }

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

class LoginFrame_jButton2_actionAdapter
    implements java.awt.event.ActionListener {
  LoginFrame adaptee;

  LoginFrame_jButton2_actionAdapter(LoginFrame adaptee) {
    this.adaptee = adaptee;
  }

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

class LoginFrame_jPasswordField1_keyAdapter
    extends java.awt.event.KeyAdapter {
  LoginFrame adaptee;

  LoginFrame_jPasswordField1_keyAdapter(LoginFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void keyReleased(KeyEvent e) {
    adaptee.jPasswordField1_keyReleased(e);
  }
}

class LoginFrame_jLabel6_keyAdapter extends java.awt.event.KeyAdapter {
  LoginFrame adaptee;

  LoginFrame_jLabel6_keyAdapter(LoginFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void keyReleased(KeyEvent e) {
    adaptee.jLabel6_keyReleased(e);
  }
}

⌨️ 快捷键说明

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