gpt4 book ai didi

java - 如何使用 JTextFields 中的 If 语句

转载 作者:行者123 更新时间:2023-11-29 03:22:56 25 4
gpt4 key购买 nike

<分区>

我已经尝试了几乎所有的方法,但我仍然无法正常运行这个该死的代码

public void Action(ActionEvent event)
{
//We get the text from the textfield
String fromUser = textfield1.getText();

if (fromUser != null) {
if(x<1)
{
if(fromUser.length() <= 10)
{
USERNAME = fromUser;
x++;
textfield1.setText("");
}
else
{
textarea1.setText("Username Surpasses Size Limit Please Try Again\nUsername Must Be 10 Characters Or Less");
textfield1.setText("");
}
}
else
{
if(x==1)
{
textarea1.setText("");
x++;
}
//We append the text from the user
textarea1.append(USERNAME+"> " + fromUser + "\n");
//The pane auto-scrolls with each new response added
textarea1.setCaretPosition(textarea1.getDocument().getLength());
//We reset our text field to "" each time the user presses Enter
textfield1.setText("");

//This is Where my code should work
if(fromUser == "n")
{
InitiateText("North");
}
else if(fromUser == "s")
{
InitiateText("South");
}
else if(fromUser == "w")
{
InitiateText("West");
}
else if(fromUser == "e")
{
InitiateText("East");
}
else
{
InitiateText("I don't comprehend");
}
}
}
}

public void InitiateText(String Where) //Where are you on the map
{
//We append the text from the user
textarea1.append("Map > " + Where + "\n");
//The pane auto-scrolls with each new response added
textarea1.setCaretPosition(textarea1.getDocument().getLength());
//We reset our text field to "" each time the user presses Enter
textfield1.setText("");
}

这是我最近的尝试,添加文本的方法工作正常,但 if 语句不起作用,我将输入“n”,它不会识别我输入的“n”。我做错了什么??

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