截屏:我正在尝试使用SceneBuilder实施警报,它正在工作。唯一的问题是,它不会等待用户在显示错误消息之前开始在字段中输入任何内容。当我单击添加零件时,它甚至在更改场景之前都会显示错误消息。我退出后,确实会更改场景,请在警报上单击“确定”。任何帮助将不胜感激。
private boolean validateInput(){
try{
double dPrice = 1.00;
dPrice = Double.parseDouble(addPartPrice.getText());
} catch (NumberFormatException | NullPointerException nfe){
AlertMessage.errorPart(3, addPartPrice);
return false;
}[enter image description here][1]
try{
int iStock = Integer.parseInt(addPartInventory.getText());
} catch (NumberFormatException | NullPointerException nfe){
return false;
}
try{
int iMin = Integer.parseInt(addPartMin.getText());
} catch (NumberFormatException | NullPointerException nfe){
return false;
}
try{
int iMax = Integer.parseInt(addPartMax.getText());
} catch (NumberFormatException | NullPointerException nfe){
return false;
}
if(!partIsoutSourcedFromCompany){
try{
int iID = Integer.parseInt(addPartSource.getText());
} catch (NumberFormatException | NullPointerException nfe){
return false;
}
}
return addPartName.getText() != null &&
addPartSource.getText() != null &&
Integer.parseInt(addPartMin.getText()) >= 0 &&
Integer.parseInt(addPartMin.getText()) <= Integer.parseInt(addPartInventory.getText()) &&
Integer.parseInt(addPartInventory.getText()) <= Integer.parseInt(addPartMax.getText()) &&
Double.parseDouble(addPartPrice.getText()) >= 0;
}
您必须将您的validateatInput方法绑定到添加按钮/功能。因此,在用户单击添加按钮之前,代码执行(即validateInput)将处于挂起状态。