import javax.microedition.rms.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

    public class RecordStoreMIDlet extends MIDlet implements CommandListener
    {
        private RecordStore rs;
        private Display display;
        private List list;
        private RecordEnumeration re;
        private Command delete, exitCommand;

        public void startApp()
        {
        try{String text = "Data 1";
      byte[] data = text.getBytes();
      rs = RecordStore.openRecordStore("RSSample", true);
      rs.addRecord(data,0,data.length);
        rs.closeRecordStore();
     } catch(Exception ex) { System.out.println(ex); }

        try {
        String data;
            list = new List("Record Store Sample", List.IMPLICIT);
            rs = RecordStore.openRecordStore("RSSample", true);
            re = rs.enumerateRecords(null,null,true);
            while(re.hasNextElement()) {
              data = new String(re.nextRecord());
              list.append(data, null);
        }
      rs.closeRecordStore();
      display = Display.getDisplay(this);
      delete = new Command("Delete", Command.OK, 2);
      list.addCommand(delete);
      list.setCommandListener(this);
        display.setCurrent(list);
     }catch(Exception ex) {System.out.println(ex);}       
       
       
        }

        protected void destroyApp(boolean unconditional)
        {
        }
        protected void pauseApp()
        {
        }
        public void commandAction(Command cmd, Displayable d)
        {
           
            if (cmd.equals(delete))
            {
                int index = list.getSelectedIndex();
                try
                {
                    rs = RecordStore.openRecordStore("RSSample", true);
                    re = rs.enumerateRecords(null, null, true);
                    int ctr = 0;
                    while (re.hasNextElement())
                    {
                        int recordid = re.nextRecordId();
                        if (ctr == index)
                            rs.deleteRecord(recordid);
                        ctr++;
                    }
                    rs.closeRecordStore();
                    list.delete(index);
                }
                catch (Exception ex) { System.out.println(ex); }   
           
            }
       
        }
    }

Currently listening to: Solomon See's Lecture
Currently feeling: geeky
Posted by jjcobwebb on June 18, 2008 at 12:47 PM in Everyday Drama, Randomness | Post a comment
Login to your account to post comment

You are not logged into your Tabulas account. Please login.