article

Tuesday, July 2, 2019

Java Swing JPasswordField & JCheckBox Usage - Login Example Tutorial

Java Swing JPasswordField & JCheckBox Usage - Login Example Tutorial
 
private void cmdloginActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if (txtusername.getText().equalsIgnoreCase("test") && txtpass.getText().equalsIgnoreCase("123")){
            if (chkremember.isSelected()){
                lblmessage.setText("Login successful with remembering option");
            }else{
                lblmessage.setText("Login successful without remembering option");
            }
        }else{
            lblmessage.setText("Login Failed");
        } 
    }
private void cmdloginActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        String userName =  txtusername.getText();
        String password =  txtpass.getText();
        if (userName.trim().equals("admin") && password.trim().equals("admin")) {
            lblmessage.setText("Hello" + userName +"");
        }else{
            lblmessage.setText("Invalid User");
        }
    }                                        

    private void cmdresetActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
         lblmessage.setText("");
         txtusername.setText("");
         txtpass.setText("");
    } 

Related Post