public void commandAction(Command command, Displayable displayable) {
if(command==exit)
{
destroyApp(true);
notifyDestroyed();
}
else if(command==start)
{
try
{
recordstore=RecordStore.openRecordStore("My RecordStore",true);
}
catch(Exception error)
{
alert=new Alert("Error Creating",error.toString(),null,AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
try
{
String outPutData[]={"Mary","Bob","Adam"};
for(int x=0;x<3;x++)
{
byte[] byteOutPutData=outPutData[x].getBytes();
recordstore.addRecord(byteOutPutData,0,byteOutPutData.length);
}
}
catch(Exception error)
{
alert=new Alert("Error Waiting",error.toString(),null,AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
try
{
byte[] byteInputData=new byte[1];
int length=0;
for(int x=1;x<=recordstore.getNumRecords();x++)
{
if(recordstore.getRecordSize(x)>byteInputData.length)
{
byteInputData=new byte[recordstore.getRecordSize(x)];
}
length=recordstore.getRecord(1,byteInputData,0);
}
alert = new Alert("Reading", new String(byteInputData, 0,length), null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
catch (Exception error)
{
alert = new Alert("Error Reading", error.toString(),null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
try
{
recordstore.closeRecordStore();
}
catch (Exception error)
{
alert = new Alert("Error Closing", error.toString(),null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
if (RecordStore.listRecordStores() != null)
{
try
{
recordstore.deleteRecordStore("MY RecordStore");
}
catch (Exception error)
{
alert = new Alert("Error Removing", error.toString(),null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
}
}
}