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

📄 loginframe.java

📁 这是一个关于信用卡的JAVA
💻 JAVA
字号:
package xinyongka;

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class loginframe
    extends JFrame {
  JPanel contentPane;
  XYLayout xYLayout1 = new XYLayout();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JPasswordField jPasswordField1 = new JPasswordField();

  private String cardid;
  private String passwordtemp;
  private Connection con;
  private ResultSet rs;

  public loginframe() {
    try {
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      jbInit();
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  /**
   * Component initialization.
   *
   * @throws java.lang.Exception
   */
  private void jbInit() throws Exception {
    contentPane = (JPanel) getContentPane();
    contentPane.setLayout(xYLayout1);
    setSize(new Dimension(400, 350));
    setTitle("登录界面");

    jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 25));
    jLabel1.setToolTipText("");
    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel1.setText("欢迎使用信用卡系统");
    jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
    jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel2.setText("卡号:");
    jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
    jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel3.setText("密码:");
    jButton1.setText("确定");
    jButton1.addMouseListener(new loginframe_jButton1_mouseAdapter(this));
    jButton2.setText("重置");
    jButton2.addActionListener(new loginframe_jButton2_actionAdapter(this));
    jTextField1.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
    jPasswordField1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
    contentPane.add(jLabel1, new XYConstraints(29, 37, 349, 49));
    contentPane.add(jLabel2, new XYConstraints(53, 137, 93, 33));
    contentPane.add(jLabel3, new XYConstraints(53, 196, 93, 29));
    contentPane.add(jTextField1, new XYConstraints(146, 137, 159, 36));
    contentPane.add(jButton1, new XYConstraints(81, 265, 92, 30));
    contentPane.add(jButton2, new XYConstraints(207, 266, 102, 31));
    contentPane.add(jPasswordField1, new XYConstraints(145, 191, 159, 36));

    //数据库驱动
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");



  }

  public void jButton1_mouseClicked(MouseEvent e) {
  cardid=jTextField1.getText().trim();
  passwordtemp="";
    for(int i=0;i<jPasswordField1.getPassword().length;i++){
     passwordtemp+=jPasswordField1.getPassword()[i];

    }
    try{

     String url="jdbc:odbc:dbcard";
     Connection conn=DriverManager.getConnection(url," "," ");
     Statement stmt=conn.createStatement();
     String loginquery="Select * from card where CardID='"+cardid +"'and Password='"+passwordtemp+"'";
     rs=stmt.executeQuery(loginquery);
     //判断返回结果
    if(rs.next()){
     eventframe eventframe1=new eventframe(cardid);
     this.dispose();
     Dimension a=new Dimension(400,350);
     eventframe1.setSize(a );
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     Dimension frameSize = eventframe1.getSize();
     if (frameSize.height > screenSize.height) {
     frameSize.height = screenSize.height;
   }
     if (frameSize.width > screenSize.width) {
     frameSize.width = screenSize.width;
   }
     eventframe1.setLocation( (screenSize.width - frameSize.width) / 2,
                              (screenSize.height - frameSize.height) / 2);
     eventframe1.setVisible(true);
   }else{
   JOptionPane.showMessageDialog(null,"用户名或密码错误,请重试!");

   }
   rs.close();
   stmt.close();
   conn.close();

    }catch(SQLException e1){

      e1.printStackTrace();
      JOptionPane.showMessageDialog(null,"数据库连接出错,请重试!");


    }


  }

  public void jButton2_actionPerformed(ActionEvent e) {
    jTextField1.setText("");
    jPasswordField1.setText("");
  }

}

class loginframe_jButton2_actionAdapter
    implements ActionListener {
  private loginframe adaptee;
  loginframe_jButton2_actionAdapter(loginframe adaptee) {
    this.adaptee = adaptee;
  }

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

class loginframe_jButton1_mouseAdapter
    extends MouseAdapter {
  private loginframe adaptee;
  loginframe_jButton1_mouseAdapter(loginframe adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jButton1_mouseClicked(e);
  }

}

⌨️ 快捷键说明

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