Java Reference
In-Depth Information
textBox.addCommand (prevCommand);
textBox.addCommand (nextCommand);
textBox.addCommand (newCommand);
textBox.setCommandListener(this);
}
public String loadEntry (int newId) throws RecordStoreException {
if (newId < 1 || newId > diary.getNumRecords()) {
byte [] data = " ".getBytes();
currentId = diary.addRecord (data, 0, data.length);
}
else
currentId = newId;
return new String (diary.getRecord (currentId)).trim();
}
public void saveEntry (String entry) throws RecordStoreException
{
byte [] data = (entry + " ").getBytes();
diary.setRecord (currentId, data, 0, data.length);
}
public void startApp() {
display = Display.getDisplay (this);
display.setCurrent (textBox);
}
public void destroyApp (boolean unconditional) {
try {
String text;
text = textBox.getString();
saveEntry (text);
diary.closeRecordStore();
}
catch (RecordStoreException e) {
throw new RuntimeException ("Cannot close Diary; reason:
"+e);
}
}
public void pauseApp() {
}
public void commandAction (Command c, Displayable d) {
try {
saveEntry (textBox.getString());
if (c == nextCommand && currentId < diary.getNumRecords())
{
textBox.setString (loadEntry (currentId+1));
}
else if (c == prevCommand && currentId > 1) {
textBox.setString (loadEntry (currentId-1));
}
else if (c == newCommand) {
textBox.setString (loadEntry (diary.getNumRecords() +
1));
}
Search WWH ::




Custom Search