Java Reference
In-Depth Information
currentEntry = (WeightEntry) database.elementAt(index - 1);
In the code fragment above, notice that WeightEntry is a simple
private utility class used to encapsulate a data record - for simplicity, it
doesn't have accessors or mutators, just public fields (i.e. it is basically a
Java version of a C struct ).
The EditEntryView class is similar to the main view as they're
both high-level screens, however in this case a number of controls are
used to allow the user to edit an existing record or to create a new
one. Notice how this class shows that you don't have to implement the
ComponentListener interface. For a simple input screen like this, we
can cheat a bit and use the softkey events to handle data validation and
updating the database:
private class EditWeightView extends Panel implements SoftKeyListener {
private ListBox cboMonths, cboDays;
private TextBox txtWeight;
private int entryId;
public EditWeightView(WeightEntry weightEntry) {
entryId = weightEntry.Id;
// populate date controls
int lastDay = Utilities.getLastDayOfMonth(weightEntry.Month,
cboDays = new ListBox(ListBox.CHOICE);
for(int i = 1; i <= lastDay; i++) {
cboDays.append(" " + i);
} cboMonths = new ListBox(ListBox.CHOICE);
for(int i = 0; i < 12; i++) {
} - 1);;
txtWeight = new
setTitle("Weight Data");
add(new Label("Day"));
add(new Label("Month"));
add(new Label("Weight (kg)"));
Search WWH ::

Custom Search