Java Reference
In-Depth Information
}
} catch (NumberFormatException e) {
TextBox tb = (TextBox)
flexEntryTable.getWidget(currentRow, currentColumn);
tb.setValue("0");
flexEntryTable.setWidget(currentRow, currentColumn, tb);
Window.alert("Not a valid number.");
}
}
};
day1.addValueChangeHandler(timeChangeHandler);
day2.addValueChangeHandler(timeChangeHandler);
day3.addValueChangeHandler(timeChangeHandler);
day4.addValueChangeHandler(timeChangeHandler);
day5.addValueChangeHandler(timeChangeHandler);
day6.addValueChangeHandler(timeChangeHandler);
day7.addValueChangeHandler(timeChangeHandler);
In the preceding timeChangeHandler method you make a call to total the current row's
entries if the user enters a valid number that is less than 24. Your method loops
through all of the time-entry TextBoxes for the current row, totals the amount, and
then sets the display text widget for the row total. Since you've changed the total of
the current row, you also want to update the total for the entire timecard. You make a
call to totalGrid, which provides that functionality.
private void totalRow() {
double rowTotal = 0.00;
for (int cell = 3;cell<=9; cell++) {
TextBox timeWidget = (TextBox)
flexEntryTable.getWidget(currentRow, cell);
double t = Double.parseDouble(timeWidget.getValue());
rowTotal = rowTotal + t;
}
flexEntryTable.setWidget(currentRow, 10, new
Label(NumberFormat.getFormat(".00").format(rowTotal)));
totalGrid();
}
Totaling the entire timecard involves the summation of the rows in the FlexTable .
Your method iterates over the current rows in the FlexTable (skipping the header row,
112
 
Search WWH ::




Custom Search