StringUtils.isNumeric 块 JOptionPane 取消选项
StringUtils.isNumeric blocks JOptionPane cancel option
这是我用来处理整数输入的代码:
public static int getIntInput(String message) {
String numberStr = JOptionPane.showInputDialog(message);
while (!StringUtils.isNumeric(numberStr) || Integer.parseInt(numberStr) == 0) {
numberStr = JOptionPane.showInputDialog(message);
}
return Integer.parseInt(numberStr);
}
它工作正常,除非我想按 "cancel" 或 JOption window 上的关闭按钮。当我这样做时,JOptionPane window 再次出现。
如何在按下取消或关闭按钮时正确关闭 JOptionPane window?
while (!StringUtils.isNumeric(numberStr) || Integer.parseInt(numberStr) == 0) {
if (numberStr == null) {
return 0;
}
else {
numberStr = JOptionPane.showInputDialog(message);
}
}
这样就可以了。
这是我用来处理整数输入的代码:
public static int getIntInput(String message) {
String numberStr = JOptionPane.showInputDialog(message);
while (!StringUtils.isNumeric(numberStr) || Integer.parseInt(numberStr) == 0) {
numberStr = JOptionPane.showInputDialog(message);
}
return Integer.parseInt(numberStr);
}
它工作正常,除非我想按 "cancel" 或 JOption window 上的关闭按钮。当我这样做时,JOptionPane window 再次出现。
如何在按下取消或关闭按钮时正确关闭 JOptionPane window?
while (!StringUtils.isNumeric(numberStr) || Integer.parseInt(numberStr) == 0) {
if (numberStr == null) {
return 0;
}
else {
numberStr = JOptionPane.showInputDialog(message);
}
}
这样就可以了。