Guest User

Untitled

a guest
Jul 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import javax.microedition.midlet.*;
  2. import javax.microedition.lcdui.*;
  3. import javax.microedition.rms.*;
  4. import java.io.*;
  5.  
  6. public class RMSDemo extends MIDlet implements CommandListener {
  7.  
  8. private Display display;
  9. private RecordStore rs=null;
  10. private Command exit;
  11. private RecordEnumeration re;
  12. private int recordNO;
  13. Form frm;
  14. int index=0;
  15. public RMSDemo() {
  16. display = Display.getDisplay(this);
  17.  
  18. //Create a RMS
  19. try {
  20. rs= RecordStore.openRecordStore("myRecord",false);
  21. rs.closeRecordStore();
  22. } catch(Exception e) {
  23. System.out.println(e);
  24. }
  25.  
  26. }
  27.  
  28. public void startApp() {
  29.  
  30. frm=new Form("RMSDemo");
  31.  
  32. exit= new Command("Exit",Command.EXIT,1);
  33. frm.addCommand(exit);
  34.  
  35. add= new Command("Add",Command.SCREN,1);
  36. frm.addCommand(add);
  37.  
  38. delete= new Command("Delete",Command.SCREEN,2);
  39. frm.addCommand(delete);
  40.  
  41. show= new Command("SHOW",Command.SCREEN ,3);
  42. frm.addCommand(show);
  43.  
  44. frm.setCommandListener(this);
  45. frm.append("#####");
  46. display.setCurrent(frm);
  47. }
  48.  
  49. public void pauseApp() {
  50.  
  51. }
  52.  
  53. public void destroyApp(boolean un) {
  54. }
  55.  
  56. // Handling commands
  57. public void commandAction(Command cmd,Displayable d) {
  58. if(cmd==add) {
  59. addRecord();
  60. } else
  61. if(cmd==delete) {
  62. removeRecord();
  63. } else
  64. if(cmd==show) {
  65. try {
  66. byte b[]= rs.getRecord(recordNO);
  67. String s= new String(b);
  68. frm.append(s);
  69. } catch(Exception e) {}
  70. }
  71. }
  72.  
  73.  
  74. void addRecord() {
  75. try {
  76. rs= RecordStore.openRecordStore("myRecord",false);
  77. index++;
  78. byte b[]=("Record NO "+index).getBytes();
  79. //Adding record to record store
  80. rs.addRecord(b,0,b.length);
  81. rs.closeRecordStore() ;
  82. } catch(Exception e) {
  83. System.out.println(e);
  84. }
  85.  
  86. }
  87.  
  88. // Deleting a record
  89. void removeRecord(int recordID) {
  90. try {
  91. rs= RecordStore.openRecordStore("myRecord",false);
  92. rs.deleteRecord(recordID);
  93. index--;
  94. rs.closeRecordStore();
  95. } catch(Exception e) {
  96. System.out.println(e);
  97. }
  98. }
  99.  
  100.  
  101. }
Add Comment
Please, Sign In to add comment