Java Reference
In-Depth Information
// from IApplication
public void start()
{
nextRecordId = 0;
database = new Vector();
// add some default data to the database
database.addElement(new WeightEntry(nextRecordId++, 26,2,85.5F));
database.addElement(new WeightEntry(nextRecordId++, 27,2,84.8F));
SwitchView(VIEW_MAIN);
}
As a matter of good practice, all view switching is centralized in
the SwitchView() method where each view is implemented by a
specialization of either the com.nttdocomo.ui.Canvas class or the
com.nttdocomo.ui.Panel class:
// switch between high-level and low-level screens based on viewId
private void SwitchView(int viewId) {
Frame view = null;
switch(viewId) {
case VIEW_MAIN: {
view = new MainView();
break;
} case VIEW_EDIT_ENTRY: {
view = new EditWeightView(currentEntry);
break;
} case VIEW_GRAPH_DATA: {
view = new GraphView();
break;
}
} Display.setCurrent(view);
}
Error handling isn't comprehensive here - the main application class
has a single method for it, which also shows how easy it is to provide
user information using the built-in Dialog class:
// handle any errors in a consistent manner
private void showError(String message) {
Dialog dialog = new Dialog(Dialog.BUTTON_OK, APP_TITLE);
dialog.setText( (message != null) ? message : "Unknown exception");
dialog.show();
}
The main application view displays the list of records using DoJa
widgets. This works in a similar manner to the AWT component
model from Java SE - a class that uses widgets should subclass the
com.nttdocomo.ui.Panel class, which acts as a container for a
group of high-level controls.
Search WWH ::




Custom Search