请多多包涵作为我是一个初学者,java的,“这样做,如果通过,那么这样做”
代码 提取物:
'CalcCost calculate = new CalcCost(); '
String key = stockNofive.getText();
String quantityTxt = quantityfive.getText();
int QuantityInt = Integer.parseInt(quantityTxt);
calculate.String(key, quantityTxt); // sending key and quantity to another class for user input check
calculate.Jlabel(stockJLBfive, quantityJLBfive); // sending jlabel for colour change if any error found
error.Colour();// recieve error value if any, if there is do not carry on,
//if error passes then do the following
calculate.setKey(key);
calculate.setQuantity(QuantityInt);
double cost = calculate.calculateBill();
information.append("\n\nTotal cost: £" + pounds.format(cost));
............
........
这是错误检查类
try {
if (key.equals("")) {
StockJLb.setText("<html><span style=\"color: red;\">Enter stock number</span></html>");
JOptionPane.showMessageDialog(null, "One or more fields missing");
return StockJLb;
}
if (QuantityStr.equals("")) {
QuantityJLb.setText("<html><span style=\"color: red;\">Enter quantity</span></html>");
JOptionPane.showMessageDialog(null, "One or more fields blank");
return QuantityJLb;
}
} catch (NumberFormatException nfe) {
QuantityJLb.setText("<html><span style=\"color: red;\">Enter quantity</span></html>");
JOptionPane.showMessageDialog(null, "'" + QuantityStr + "' is not a number");
error= true;
return QuantityJLb;
}
如果需要更多的代码或其他任何东西,现在已停留2周,请回复。 即时通讯如果仍然unlclear我把代码中的笔记帮助, 我想代码是如果有错误不进行计算,如果没有,它通过错误检查做的计算,ive试过如果statments,并尝试添加布尔值,但仍然无法算起来,
也许你可以放些更多的代码来理解上下文以及你想做什么。 – 2013-03-12 14:35:13
错误通过的含义是什么? – 2013-03-12 14:36:35
你的问题是非常不清楚,从我看到我只是建议你阅读关于try/catch块:-) – Gatekeeper 2013-03-12 14:37:41