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

📄 login.java~95~

📁 这是Java数据库系统项目开发实践源代码,所有代码经过测试
💻 JAVA~95~
字号:
package enterpriseemployeeadministrate;
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import com.borland.dx.sql.dataset.*;
import java.sql.*;


public class Login extends JDialog{

  XYLayout xYLayout1 = new XYLayout();

  private String userName = "";
  private String password = "";

  XYLayout xYLayout2 = new XYLayout();
  XYLayout xYLayout3 = new XYLayout();
  XYLayout xYLayout4 = new XYLayout();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JPasswordField jPasswordField1 = new JPasswordField();

  Database database1 = new Database();
  QueryDataSet queryDataSet1 = new QueryDataSet();
  Frame1 parentFrame ;
  public Login(Frame1 parent) {
    super(parent, true);
    parentFrame = parent;
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }



  private void jbInit() throws Exception {
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 13));
    jLabel1.setMinimumSize(new Dimension(61, 19));
    jLabel1.setText("user name");
    this.getContentPane().setLayout(xYLayout4);
    this.setLocation(200,200);
    this.getContentPane().setBackground(UIManager.getColor("InternalFrame.activeTitleGradient"));
    this.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
    this.setFont(new java.awt.Font("Dialog", 0, 12));
    this.setForeground(UIManager.getColor("info"));
    this.setJMenuBar(null);
    this.setModal(true);
    this.setResizable(true);
    this.setTitle("login dialog");
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 13));
    jLabel2.setText("password");
    jButton1.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton1.setText("ok");
    jButton1.addActionListener(new LoginDialog_jButton1_actionAdapter(this));
    jButton2.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton2.setText("cancel");
    jButton2.addActionListener(new LoginDialog_jButton2_actionAdapter(this));
    jPasswordField1.setText("");
    jTextField1.setText("");
    xYLayout4.setWidth(419);
    xYLayout4.setHeight(307);
    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:person", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
    this.getContentPane().add(jLabel1, new XYConstraints(44, 39, 77, 20));
    this.getContentPane().add(jLabel2, new XYConstraints(46, 79, 82, 27));
    this.getContentPane().add(jPasswordField1, new XYConstraints(142, 83, 116, 24));
    this.getContentPane().add(jTextField1, new XYConstraints(142, 38, 116, 24));
    this.getContentPane().add(jButton1, new XYConstraints(52, 143, 77, 27));
    this.getContentPane().add(jButton2, new XYConstraints(182, 142, -1, 27));
    setSize(330,250);
  }



int userType=0;
  void jButton1_actionPerformed(ActionEvent e) {

     //读出用户名和密码
     String user=jTextField1.getText();
     String password=jPasswordField1.getText();

     //将用户名和密码变成查询语句即将使用的形式
     user="'"+user+"'";
     password="'"+password+"'";

     //先将查询语句关闭掉,为下一次的使用做准备
     queryDataSet1.close();

     //设置查询语句
     queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1,
         "select user_type from user_info where user_name= "+user+" and user_password= "+ password));

     //执行查询语句
     queryDataSet1.executeQuery();

     //获得查询语句的结果(用户的类型),待用
     userType=Integer.parseInt(queryDataSet1.getString("user_type"));
     //如果获得不了用户类型,表示这样的用户名和密码不存在,提示信息错误
     if(userType==0)
       JOptionPane.showMessageDialog(this,"please enter correct infomation","error",JOptionPane.ERROR_MESSAGE);
//如果用户名和密码都正确,设置这一个界面不可见,回到主界面
     else {this.setVisible(false);}

     parentFrame.userTypeInfo = userType;
        this.dispose() ;
  }



  class LoginDialog_jButton1_actionAdapter implements java.awt.event.ActionListener {
    Login adaptee;

    LoginDialog_jButton1_actionAdapter(Login adaptee) {
      this.adaptee = adaptee;
    }
    public void actionPerformed(ActionEvent e) {
      adaptee.jButton1_actionPerformed(e);
    }

  }


  void jButton2_actionPerformed(ActionEvent e) {
  setVisible(false);
  }

  void jTextField4_actionPerformed(ActionEvent e) {
  }

  class LoginDialog_jButton2_actionAdapter
      implements java.awt.event.ActionListener {
    Login adaptee;

    LoginDialog_jButton2_actionAdapter(Login adaptee) {
      this.adaptee = adaptee;
    }

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

  }

  class LoginDialog_jTextField4_actionAdapter
      implements java.awt.event.ActionListener {
    Login adaptee;

    LoginDialog_jTextField4_actionAdapter(Login adaptee) {
      this.adaptee = adaptee;
    }

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

public String getUserName(){return userName;}

}


class LoginDialog_jButton2_actionAdapter implements java.awt.event.ActionListener {
  Login adaptee;

  LoginDialog_jButton2_actionAdapter(Login adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class LoginDialog_jButton1_actionAdapter implements java.awt.event.ActionListener {
  Login adaptee;

  LoginDialog_jButton1_actionAdapter(Login adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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