Always proceeds to else condition, i've used char[] also for comparison it seems to have a logical error instead of a syntax.
JButton Logb = new JButton("Go");
String name="Wijdan";
char[] password=passwordField.getPassword();
char[] pass=new char[]{'l','o','g','i','n'};
Logb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(namefield.getText().equals(name) && Arrays.equals(password, pass)){
namefield.setText("brr");
passwordField.setText("brr");
}
else {
JOptionPane.showMessageDialog(null, "Invalid username or password");
}
}
});
Logb.setFont(new Font("Tahoma", Font.PLAIN, 25));
Logb.setBounds(180, 190, 89, 39);
contentPane.add(Logb);
}
You're calling getPassword() before the user had a chance to enter the password. You need to move the getPassword() call into the actionPerformed() method, so that it would compare the actual entered password, and not the empty password which was displayed in the form initially.
Also please consider using a debugger to understand how your code works. If you set a breakpoint inside the actionPerformed() method, you will be able to see the exact values being compared and understand why they are not correct.