import javax.microedition.midlet.*; import javax.microedition.rms.*; import javax.microedition.lcdui.*; import java.io.*; public class Salvestus1a extends MIDlet{ String hoidlanimi="hoidla1a"; protected void startApp() throws MIDletStateChangeException{ try{ RecordStore rs=RecordStore.openRecordStore(hoidlanimi, true); int arv=1; if(rs.getNumRecords()==0){ byte[] bm=intBaitideks(arv+1); rs.addRecord(bm, 0, bm.length); } else { arv=baididIntiks(rs.getRecord(1)); byte[] bm=intBaitideks(arv+1); rs.setRecord(1, bm, 0, bm.length); } rs.closeRecordStore(); Alert a=new Alert("Loendur", arv+". kord", null, AlertType.CONFIRMATION); a.setTimeout(Alert.FOREVER); Display.getDisplay(this).setCurrent(a); }catch(Exception e){e.printStackTrace();} } protected void pauseApp(){} protected void destroyApp(boolean kohustus) throws MIDletStateChangeException{} byte[] intBaitideks(int a) throws IOException{ ByteArrayOutputStream bos=new ByteArrayOutputStream(); DataOutputStream dos=new DataOutputStream(bos); dos.writeInt(a); dos.close(); return bos.toByteArray(); } int baididIntiks(byte[] b) throws IOException { ByteArrayInputStream bis=new ByteArrayInputStream(b); DataInputStream dis=new DataInputStream(bis); return dis.readInt(); } }