-1
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String a,b;
    a=jTextField1.getText();
    b=Arrays.toString(jPasswordField2.getPassword());
    if (a.equals("sam") && b.equals("hi")) {
        JOptionPane.showMessageDialog(null,"Login");
    }
    else{
        JOptionPane.showMessageDialog(null,"Error");
    }
} 

only else part being executed, when using "or" operator if part works. seems to have error in "and" condition.

SAm
  • 1
  • 1

2 Answers2

0

Arrays.toString(new String[]{"hi"}) returns "[hi]".

So you should change your if to if (a.equals("sam") && b.equals("[hi]")) or your value of b to b=jPasswordField2.getPassword()[0];.

Stefan Warminski
  • 1,845
  • 1
  • 9
  • 18
0

getpassword method returns the password into brackets. return will be like this: [hi]. So you must use delete brackets. use a code like blow:

    b=b.substring(1,b.length()-1);

This code will delete the brackets in your password string.