您好,我在这里要做的是接收用户输入的密码,然后将其与 if 语句中的正确密码进行比较。
public void actionPerformed(ActionEvent event)
{
String UsersStoredPassword = "hello";
String UsersEnteredPassword = new String(PasswordField.getPassword());
String Message = "The Password You Have Entered Is Correct";
String Message1 = "You Have Entered The Wrong Password";
if (event.getSource() == PasswordField)
{
if (UsersEnteredPassword == UsersStoredPassword)
{
JOptionPane.showMessageDialog(null, Message);
}
else
{
JOptionPane.showMessageDialog(null, Message1);
}
}
}
然而事件认为用户输入了正确的密码:“你好”它仍然显示消息1:“你输入了错误的密码。我试过这样做:
public class TheHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String UsersStoredPassword = "hello";
String UsersEnteredPassword = new String(PasswordField.getPassword());
String Message = "The Password You Have Entered Is Correct";
String Message1 = "You Have Entered The Wrong Password";
if (event.getSource() == PasswordField)
{
JOptionPane.showMessageDialog(null, UsersEnteredPassword);
}
}
}
它显示在里面输入的 UsersEnteredPassword。