Translate it in English.

huangapple go评论77阅读模式
英文:

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 &quot;!&quot; means &quot;not&quot; but I still don&#39;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(&quot;&quot;))

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(&quot;&quot;))

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

&gt; (nameTextField.getText()).equals(&quot;&quot;)

这将在文本视图为空时返回true
因此

&gt;if(!(nameTextField.getText()).equals(&quot;&quot;))

整行代码的意思是检查您的文本视图是否为空如果文本视图不为空它将返回*false*&quot;!&quot;会将其转换为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(&quot;&quot;)) 的意思是:
如果 nameTextField 的 文本内容不为空,则执行 validationBoolean = true;<br>
但如果 nameTextField 的 文本内容为空,则创建一个警示对话框(会要求输入)。

英文:

The line if(!(nameTextField.getText()).equals(&quot;&quot;)) 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).

huangapple
  • 本文由 发表于 2020年10月13日 13:00:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64328785.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定