javafx 密码字段文本
javafx PasswordField text
我对 javafx 有一些奇怪的问题PasswordField.this 是我的代码:
public class Form1 implements Initializable {
@FXML private PasswordField pass;
@FXML private PasswordField confpass;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
}
public void btn1_onclick(ActionEvent event){
String password = pass.getText();
String conf = confpass.getText();
if(conf == password)
{
System.out.println(":)");
}
else
{
System.out.println(password + "\t" + conf);
}
}
}
我在两个 PasswordField 中输入相同的词,但 if 条件始终为假,我在控制台中看到两个相同的词!!!
我该如何解决这个问题?
使用equals()
比较字符串
conf.equals(password)
我对 javafx 有一些奇怪的问题PasswordField.this 是我的代码:
public class Form1 implements Initializable {
@FXML private PasswordField pass;
@FXML private PasswordField confpass;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
}
public void btn1_onclick(ActionEvent event){
String password = pass.getText();
String conf = confpass.getText();
if(conf == password)
{
System.out.println(":)");
}
else
{
System.out.println(password + "\t" + conf);
}
}
}
我在两个 PasswordField 中输入相同的词,但 if 条件始终为假,我在控制台中看到两个相同的词!!!
我该如何解决这个问题?
使用equals()
比较字符串
conf.equals(password)