JavaFX - 文本区域未填充时发出警报
JavaFX - Alert when text areas are not filled
我遇到了一些小问题,找不到解决方案。
我创建了一些输入文本区域。他们将输入转换为字符串并将它们作为 .txt 文件保存在目录中。
我想创建当用户单击“提交”按钮时调用的方法,并检查是否填写了所有请求的字段,如果没有填写,则应显示错误警报。
checkRequestedFields();
String dbSubjectField = inputSubject_field.getText();
String dbLocationField = "Location: " + inputLocation_field.getText() + "\n";
String dbDescriptionArea = "Description: " + inputDescription_area.getText() + "\n";
String dbDate = "Date: " + inputCalendar_datePicker.getValue().toString() + "\n";
String dbCheckBoxImportance = isSelected() + "\n";
try
{
FileWriter save = new FileWriter("Reminders/" + inputSubject_field.getText() + ".txt");
BufferedWriter bf = new BufferedWriter(save);
bf.write(dbDate + dbLocationField + dbDescriptionArea + dbCheckBoxImportance);
bf.close();
}
catch (IOException ex)
{
}
inputDescription_area.clear();
inputSubject_field.clear();
inputLocation_field.clear();
inputCalendar_datePicker.setValue(null);
inputImportance_checkBox.setSelected(false);
}
public void checkRequestedFields()
{
if(inputSubject_field.getText() == null || inputLocation_field.getText() == null || inputCalendar_datePicker.getValue().toString() == null || inputDescription_area.getText() == null)
{
Alert alert = new Alert(Alert.AlertType.ERROR);
String content = "Please fill all requested fields";
alert.setContentText(content);
alert.showAndWait();
}
else
{
}
}
});
不知道我的方法是否正确,但对我来说很有意义。
如果选定的输入文本区域之一为空(null),则应出现警报。但是当我点击提交按钮时没有任何反应。控制台中出现很多错误。
"Empty" 与 null
不同。使用
inputSubject_field.getText().isEmpty()
或者也许
inputSubject_field.getText().trim().isEmpty()
等
我遇到了一些小问题,找不到解决方案。 我创建了一些输入文本区域。他们将输入转换为字符串并将它们作为 .txt 文件保存在目录中。 我想创建当用户单击“提交”按钮时调用的方法,并检查是否填写了所有请求的字段,如果没有填写,则应显示错误警报。
checkRequestedFields();
String dbSubjectField = inputSubject_field.getText();
String dbLocationField = "Location: " + inputLocation_field.getText() + "\n";
String dbDescriptionArea = "Description: " + inputDescription_area.getText() + "\n";
String dbDate = "Date: " + inputCalendar_datePicker.getValue().toString() + "\n";
String dbCheckBoxImportance = isSelected() + "\n";
try
{
FileWriter save = new FileWriter("Reminders/" + inputSubject_field.getText() + ".txt");
BufferedWriter bf = new BufferedWriter(save);
bf.write(dbDate + dbLocationField + dbDescriptionArea + dbCheckBoxImportance);
bf.close();
}
catch (IOException ex)
{
}
inputDescription_area.clear();
inputSubject_field.clear();
inputLocation_field.clear();
inputCalendar_datePicker.setValue(null);
inputImportance_checkBox.setSelected(false);
}
public void checkRequestedFields()
{
if(inputSubject_field.getText() == null || inputLocation_field.getText() == null || inputCalendar_datePicker.getValue().toString() == null || inputDescription_area.getText() == null)
{
Alert alert = new Alert(Alert.AlertType.ERROR);
String content = "Please fill all requested fields";
alert.setContentText(content);
alert.showAndWait();
}
else
{
}
}
});
不知道我的方法是否正确,但对我来说很有意义。 如果选定的输入文本区域之一为空(null),则应出现警报。但是当我点击提交按钮时没有任何反应。控制台中出现很多错误。
"Empty" 与 null
不同。使用
inputSubject_field.getText().isEmpty()
或者也许
inputSubject_field.getText().trim().isEmpty()
等