首页上一页 1 下一页尾页 1 条记录 1/1页
《java从入门到精通》P512
发表在Java图书答疑
2010-10-14
是否精华
是
否
版块置顶:
是
否
我买的是Java从入门到精通的第一版在该书的P512页的进货统计有这样一个方法
private final void ComputeInfo() {
// 计算代码
int rows = table.getRowCount();
int count = 0;
double money = 0.0;
// 计算品种数量
TbSpinfo column = null;
Object valueAt = table.getValueAt(rows - 1, 0);
if(!(valueAt instanceof TbSpinfo))
return;
if (rows > 0)
column = (TbSpinfo) valueAt;
if (rows > 0 && (column == null || column.getId().isEmpty()))
rows--;
// 计算货品总数和金额
for (int i = 0; i < rows; i++) {
String column7 = (String) table.getValueAt(i, 7);
String column6 = (String) table.getValueAt(i, 6);
int c7 = (column7 == null || column7.isEmpty()) ? 0 : Integer
.parseInt(column7);
float c6 = (column6 == null || column6.isEmpty()) ? 0 : Float
.parseFloat(column6);
count += c7;
money += c6 * c7;
}
pzslField.setText(rows + "");
hpzsField.setText(count + "");
hjjeField.setText(money + "");
}
我思考了半天还是不明白,而书上没有详细的解释,还请各位老师详细的解释一下,非常感谢
private final void ComputeInfo() {
// 计算代码
int rows = table.getRowCount();
int count = 0;
double money = 0.0;
// 计算品种数量
TbSpinfo column = null;
Object valueAt = table.getValueAt(rows - 1, 0);
if(!(valueAt instanceof TbSpinfo))
return;
if (rows > 0)
column = (TbSpinfo) valueAt;
if (rows > 0 && (column == null || column.getId().isEmpty()))
rows--;
// 计算货品总数和金额
for (int i = 0; i < rows; i++) {
String column7 = (String) table.getValueAt(i, 7);
String column6 = (String) table.getValueAt(i, 6);
int c7 = (column7 == null || column7.isEmpty()) ? 0 : Integer
.parseInt(column7);
float c6 = (column6 == null || column6.isEmpty()) ? 0 : Float
.parseFloat(column6);
count += c7;
money += c6 * c7;
}
pzslField.setText(rows + "");
hpzsField.setText(count + "");
hjjeField.setText(money + "");
}
我思考了半天还是不明白,而书上没有详细的解释,还请各位老师详细的解释一下,非常感谢