gpt4 book ai didi

java - 如何使用 if else 在 TextField 中设置 var 值

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:39:19 26 4
gpt4 key购买 nike

请问如何立即将名为 txtUserName 的 TextField 等于“Aime”,并将我的 txtPassword 等于“Joy”,以便它显示消息“用户名和密码匹配!” ?任何人?请帮助我:(

public void actionPerformed(ActionEvent e){
if (e.getSource()== btnClear){
txtUserName.setText("");
}
if(e.getSource() == btnLogin){
if (txtUserName.setText="Aime" && txtPassword.setText="JOy")){
JOptionPane.showMessageDialog(null, "User Name and Password Match!");
}
else {
JOptionPane.showMessageDialog(null, "User Name and Password Invalid!");
}

最佳答案

这些是需要的小修改。

if (txtUserName.getText().equals("Aime") && txtPassword.getText().equals("Joy")){
JOptionPane.showMessageDialog(null, "User Name and Password Match!");
}else{
JOptionPane.showMessageDialog(null, "User Name and Password Invalid!");
}

供您引用:What is the difference between == vs equals() in Java?

关于java - 如何使用 if else 在 TextField 中设置 var 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46172690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com