所以我正在为学校设计一个程序,部分任务是弹出一堆输入提示。我正在使用 JOptionPane,它本来就有一个 OK 按钮和一个 Cancel 按钮。现在,为了让程序在提示要求输入字符串时按取消时退出,我有这样的事情:
firstName = JOptionPane.showInputDialog("Please enter your first name:");
if(firstName == null)System.exit(0);
但我也必须对输入的数字做同样的事情,包括双精度数和整数。如果我尝试同样的事情,它会抛出一个错误,说 The operator == is undefined for the argument type(s) double, null。那么,当提示输入数值时,我检查他们是否单击取消的最佳方法是什么?谢谢你的帮助!
编辑#1
这是 JOptionPane 获取数值的代码:
startDateMonth = Integer.parseInt(JOptionPane.showInputDialog("Please enter the start date month (1-12):"));