Java Reference
In-Depth Information
// set self as listener
setSoftLabel(Frame.SOFT_KEY_1, "Save");
setSoftLabel(Frame.SOFT_KEY_2, "Back");
setSoftKeyListener(this);
}
// from SoftKeyListener
public void softKeyPressed(int softKey) {}
public void softKeyReleased(int softKey)
{
try {
if(softKey == Frame.SOFT_KEY_1) { // Save
float weight = getInputWeight();// may throw exception
int day = Integer.parseInt(
cboDays.getItem(cboDays.getSelectedIndex()));
int month = cboMonths.getSelectedIndex();
if(entryId == -1) // new record
database.addElement(
new WeightEntry(nextRecordId++, day, month, weight));
else // update database with specified values
updateWeightRecord(entryId, day, month, weight);
SwitchView(VIEW_MAIN);
} else if(softKey == Frame.SOFT_KEY_2) // Back
SwitchView(VIEW_MAIN);
} catch(Exception e) {
showError(e.getMessage());
}
}
In the listing above, the methods getInputWeight() and update-
WeightRecord() are not shown - these are private methods in this
class. Their full implementation is included in the downloadable source
code. For convenience, a number of methods not shown above that are
useful for date information management have been included in a separate
static class called Utilities .
7.6.2 Low-level API
Let's move away from the high-level API now and have a look at using
the low-level one. There's nothing particularly special about this and
certainly the basics are very similar to what you are used to with MIDP
2.0. The main difference to be aware of when you get started is in how
double buffering is handled. In MIDP, you can do it yourself or, if you're
using a Symbian implementation, the Canvas class is double-buffered
by default. It's a little different in DoJa - you use two methods on the
graphics context called lock() and unlock() and place your drawing
code between them, as you'll see below.
The GraphView class subclasses com.nttdocomo.ui.Canvas and
draws a simple line graph representing the distribution of weights in the
 
Search WWH ::




Custom Search