import javax.microedition.midlet.*; import javax.microedition.rms.*; import javax.microedition.lcdui.*; import java.io.*; public class Salvestus2 extends MIDlet implements CommandListener{ String hoidlanimi="hoidla2"; Form f=new Form("Sünnipäevad"); Command lisa=new Command("Lisa", Command.SCREEN, 1); TextField tfnimi=new TextField("Eesnimi", "", 20, TextField.ANY); DateField dfsynniaeg=new DateField("Sünnipäev", DateField.DATE); RecordStore rs; public Salvestus2(){ f.append(tfnimi); f.append(dfsynniaeg); f.addCommand(lisa); try{ rs=RecordStore.openRecordStore(hoidlanimi, true); }catch(Exception e){teade(e.getMessage());} } protected void startApp() throws MIDletStateChangeException{ Display.getDisplay(this).setCurrent(f); } protected void pauseApp(){} protected void destroyApp(boolean kohustus) throws MIDletStateChangeException{ try{ rs.closeRecordStore(); } catch (Exception e){teade(e.getMessage());} } public void commandAction(Command c, Displayable d){ if(c==lisa){ lisaKirje(); } } void lisaKirje(){ byte[] bm=leiaBaidiMassiiv(); try{ rs.addRecord(bm, 0, bm.length); }catch(Exception e){ teade(e.getMessage()); } } byte[] leiaBaidiMassiiv(){ ByteArrayOutputStream bos=new ByteArrayOutputStream(); DataOutputStream dos=new DataOutputStream(bos); try{ dos.writeUTF(tfnimi.getString()); dos.writeLong(dfsynniaeg.getDate().getTime()); }catch(Exception e){teade(e.getMessage());} return bos.toByteArray(); } void teade(String teade){ Alert a=new Alert("Teade", teade, null, AlertType.CONFIRMATION); a.setTimeout(5); Display.getDisplay(this).setCurrent(a); } }