英文:
Translate it in english
问题
if (!(nameTextField.getText()).equals("")) {
validationBoolean = true;
} else {
AlertDialog("Name", "Customer Name", "Please enter name");
nameTextField.requestFocus();
validationBoolean = false;
}
我的老师给了我们这个GUI项目要做,大部分我都理解了,但是这部分不太懂。我知道 "!" 的意思是 "not",但我仍然不明白这行代码在说什么。我想知道是否有人可以帮助我理解这个循环。
<details>
<summary>英文:</summary>
if(!(nameTextField.getText()).equals("")) {
validationBoolean = true;
}
else {
AlertDialog("Name","Customer Name","Please enter name");
nameTextField.requestFocus();
validationBoolean = false;
}
My teacher gave us this GUI project to do, I understood everything for the most part but this. I know "!" means "not" but I still don't get what this line of code is saying. I was wondering if someone can help me understand this loop.
</details>
# 答案1
**得分**: 2
如果名称文本字段的文本不为空(不等于“”),则将验证布尔值设置为true;否则,显示警示对话框,将焦点设置在名称文本字段上,并将验证布尔值设置为false。
让我们分解第一行代码,
```java
if (!(nameTextField.getText()).equals(""))
首先,通过使用 nameTextField.getText()
从 nameTextField
获取文本。
其次,检查它是否等于“”,即检查文本是否为空。
最后,使用 !
反转条件,以便在文本不为空时执行 if
代码块。
英文:
If the name text field's text is not empty (not equal to "") then set the validation boolean = true else, Show an alert dialog, set focus on the name text field and set validation boolean to false
Let's break the first line,
if(!(nameTextField.getText()).equals(""))
Firstly, get the text from nameTextField
by using nameTextField.getText()
Secondly, Check if it is equal to "", i.e. check if the text is empty.
Finally, invert the condition using !
so that the if
block gets executed when the text is not empty.
答案2
得分: 1
if(!(nameTextField.getText()).equals(""))
如果 nameTextField
的文本不为空 (""),则为有效。否则(如果为空),它将提示输入。
英文:
if(!(nameTextField.getText()).equals(""))
If text of the nameTextField
is not blank ("") then it's valid. Else (if it's blank) it will prompt for Inputs
答案3
得分: 0
如果您的 nameTextField
为空,则您的 validationBoolean
将被设置为 true。
如果 nameTextField
不为空,则会出现一个对话框,询问“Name”、“Customer Name”和“Please enter name”,然后 validationBoolean
将被设置为 false。
英文:
if your nameTextField
is empty then your validationBoolean
will be assigned as true.
if nameTextField
is not empty then a dialogue will occur with asking "Name", "Customer Name" and "Please enter name" and then the validationBoolean
will be assigned as false.
答案4
得分: 0
检查在nameTextField中输入的值是否为空,并在这种情况下将该值视为有效。请注意,任何空白字符都会通过这个简单的验证,这就是为什么通常在此之前会调用trim()。顺便提一下,这不是一个循环,而是一个if语句。
英文:
It checks that the value entered in nameTextField is not empty and considers the value valid in this case. Note that any whitespace character passes this simple validation, that's why you usually call trim() beforehand. And FYI, this is not a loop, this is an if statement.
答案5
得分: 0
> (nameTextField.getText()).equals("")
这将在文本视图为空时返回true。
因此,
>if(!(nameTextField.getText()).equals(""))
整行代码的意思是检查您的文本视图是否为空。如果文本视图不为空,它将返回*false*,而"!"会将其转换为true。因此,如果您的文本视图不为空,if条件将为true,并且if块内的代码将被执行。
英文:
> (nameTextField.getText()).equals("")
This will return true if your textview is empty.
So
>if(!(nameTextField.getText()).equals(""))
this whole line means it is checking if your textview is empty or not. If your textview is not empty, it will return a false and the "!" will turn it into true. So if your textview is not empty the if condition will be true and the code insde the if block will execute.
答案6
得分: 0
这行代码 if(!(nameTextField.getText()).equals(""))
的意思是:
如果 nameTextField 的 文本内容不为空,则执行 validationBoolean = true;
<br>
但如果 nameTextField 的 文本内容为空,则创建一个警示对话框(会要求输入)。
英文:
The line if(!(nameTextField.getText()).equals(""))
says:
if the text of the nameTextField is not empty then do validationBoolean = true;
<br>
but if the text of the nameTextField is empty then create a alert dialog (which will ask for input).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论