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

📄 login.java

📁 Java banking application with GUI add/delete/update new account partially generic GUI
💻 JAVA
字号:
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.Container;
import javax.swing.JOptionPane;
import java.awt.FlowLayout;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.sql.ResultSet;
import java.sql.Statement;

public class Login
    extends JFrame {

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

  private JTextField UserField = new JTextField();
  private JPasswordField passwordField = new JPasswordField();
  private JButton submit = new JButton();

  public Login() {
	  super("Login");
    Container contentpane = getContentPane();
    contentpane.setLayout(new FlowLayout());

    JPanel jp1=new JPanel();
    jp1.setLayout(new GridLayout(2,2));

    jp1.add(new JLabel("username"));

    UserField=new JTextField(10);
    jp1.add(UserField);

    jp1.add(new JLabel("password"));
    passwordField=new JPasswordField(10);
    jp1.add(passwordField);
    contentpane.add(jp1);

    submit=new JButton("submit");
    submit.addActionListener(new ButtonListener(this));
    contentpane.add(submit);
    setBounds(200,200,300,150);
    //setSize(300,150);
    setVisible(true);

  }



  private class ButtonListener
      implements ActionListener {
    Login jframe;
    public ButtonListener(Login f) {
      jframe = f;
    }

    public void actionPerformed(ActionEvent e) {
      String password = String.copyValueOf(passwordField.getPassword());
      String username = UserField.getText();
      if ( (password.equals("")) || (username.equals(""))) {
        JOptionPane.showMessageDialog(null, "Fill Both Username AND Password");
      }
      else {
        if (authenticate(username,password)) {
          jframe.setVisible(false);
          MainMenu main=new MainMenu();
        }
        else {
          JOptionPane.showMessageDialog(null, "Wrong Username Or Password");
        }
      }
    }

  private String query;
  private ServiceLocater sl=ServiceLocater.getInstance();
  private Statement statement=sl.createStatement();

  public boolean authenticate(String username,String password) {
    ResultSet results = null;
    try {
      String query = "Select * from Administrator where  username like '" +
          username + "' AND password like '" + password +
          "'";
      results = statement.executeQuery(query);
      if (results.next()) {
        System.out.println("result" + results.getString("username") +results.getString("password"));
        return true;
      }

    }
    catch (Exception e) {
      System.out.println("Exception in authenticate" + e);
    }
    return false;
  }

  }
}

⌨️ 快捷键说明

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