/* * mysec.java * * Created on 5.02.2004 */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.rms.*; /** * An example MIDlet that stores the number of its executions. * Refer to the startApp, pauseApp, and destroyApp * methods so see how each handles the requested transition. * * @author prjsoft.ru * @version */ public class mysec extends MIDlet implements CommandListener { private Command exitCommand; // The exit command private Display display; // The display for this MIDlet private RecordStore rs=null; private byte[] data; public mysec() { data=new byte[1]; data[0]=1; display = Display.getDisplay(this); exitCommand = new Command("Exit", Command.SCREEN, 2); } /** * Start up the store MIDlet by creating the TextBox and associating * the exit command and listener. */ public void startApp() { try { rs = RecordStore.openRecordStore( "mydata", true ); if(rs.getNumRecords()==0) rs.addRecord( data, 0, data.length ); else { rs.getRecord(1,data,0); data[0]++; rs.setRecord(1,data,0, data.length); } rs.closeRecordStore(); } catch( RecordStoreFullException e ){ // no room left for more data } catch( RecordStoreNotOpenException e ){ // store has been closed } catch( RecordStoreException e ){ // general error } TextBox t = new TextBox("number of starts is", String.valueOf(data[0]), 256, 0); t.addCommand(exitCommand); t.setCommandListener(this); display.setCurrent(t); } /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { } /* * Respond to commands, including exit * On the exit command, cleanup and notify that the MIDlet has been destroyed. */ public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } }