【发布时间】:2015-10-24 09:04:22
【问题描述】:
我的问题很小,找不到解决方案。 我创建了一些输入文本区域。他们正在将输入转换为字符串并将它们作为 .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),则应出现警报。但是当我单击提交按钮时没有任何反应。只是控制台出现了很多错误。
【问题讨论】:
-
你能发布错误吗?
-
感谢您的关注。 James_D 的回答有帮助!