私は登録フォームを使用してプロジェクトに取り組んでいます。フォームは、ユーザーが選択したパスワードを JPassword フィールドに入力し、別の JPassword フィールドに再度入力するように求めます。
パスワードが一致しない場合にユーザーにプロンプトを表示するために JOptionPane を使用しています。しかし、2つで passwordField.getPassword().toString() を使用すると、一致しません。たとえば、両方で基本的な「12345」を入力しようとしましたが、まだ運がありません。
.equals() を使用する必要があることはわかっていますが、「!=」演算子を使用せずに「等しくない」と同等のものは何ですか。
ここに次のコードがあります。
if(e.getSource() == submit)
{
String name = nameTextField.getText();
String address = addressTextField.getText();
String phoneNumber = numberTextField.getText();
String dob = datePicker.getDateFormatString();
String password = passwordField.getPassword().toString();
String password2 = passwordFieldTwo.getPassword().toString();
try
{
//If the user leaves the field empty
if(name == null || address == null || phoneNumber == null || dob == null
|| password == null || password2 == null)
{
//Error message appears to prompt the user to
//complete the form
JOptionPane.showMessageDialog(null, "All fields must be complete to submit.", "Woops", JOptionPane.ERROR_MESSAGE);
}
if(password != password2)
{
JOptionPane.showMessageDialog(null, "Passwords do not match.", "Woops", JOptionPane.ERROR_MESSAGE);
passwordField.setText(null);
passwordFieldTwo.setText(null);
}
これについての助けは大歓迎です。