我有这个取消按钮的问题。
这些代码:
int deposit;
String dep =
JOptionPane.showInputDialog("How much would you like to deposit?\n\t$: ");
deposit = Integer.parseInt(dep);
应该会出现“确定”和“取消”按钮,但是每当我单击“取消”按钮时,都没有任何响应。我想要的是,每当我单击“取消”按钮时,它都应返回主菜单,但是如何?
编码:
private static void processDeposit(String num, int rc){
int deposit;
String dep =
JOptionPane.showInputDialog(
"How much would you like to deposit?\n\t$: ");
deposit = Integer.parseInt(dep);
JOptionPane.showMessageDialog(
null, "You have deposited $" + dep + " into the account of " + name);
myAccount.setBalance(myAccount.getBalance() + deposit);
}
最佳答案
如果用户单击“取消”,则dep将返回null
因此,您可以执行以下操作:
if(input == null || (input != null && ("".equals(input))))
{
//what you ever you need to do here
}
关于java - 取消按钮必须具有功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14859256/