import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io....
public WREx2 ()
{
d = Display.getDisplay(this);
exit = new
Command("Exit", Command.EXIT, 1);
//exit = new
Command("Exit", ...
public void startApp()
{
d.setCurrent(f);
}
public void pauseApp()
{
}
public void destroyApp( boolean b )
{
}
public void...
else if (c == start)
{
try
{
rec =
RecordStore.openRecordStore("myRecordStore
", true );
}
catch (Exception e)
{
/*a = new...
//String oS = "First Record";
String oS = "Rama Rao";
int oI = 15;
boolean oB = true;
//ByteArrayOutputStream outputStream...
try
{
String s = null;
int i = 0;
boolean b = false;
byte[] by = new byte[100];
ByteArrayInputStream ist = new
ByteArrayIn...
for (int x = 1; x <= rec.getNumRecords(); x++)
{
rec.getRecord(x, by, 0);
s = ids.readUTF();
b = ids.readBoolean();
i = id...
ist.close();
ids.close();
a = new Alert("Reading", s + " " +i + " " + b,
null, AlertType.WARNING);
a.setTimeout(Alert.FORE...
if (RecordStore.listRecordStores() != null)
{
try
{
RecordStore.deleteRecordStore("myRecordStor
e");
}
catch (Exception er...
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Wr ex2
Upcoming SlideShare
Loading in …5
×

Wr ex2

289 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
289
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Wr ex2

  1. 1. import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.midlet.MIDlet; import javax.microedition.rms.RecordStore; public class WREx2 extends MIDlet implements CommandListener { private Display d; private Alert a; private Form f; private Command exit; private Command start; private RecordStore rec = null;
  2. 2. public WREx2 () { d = Display.getDisplay(this); exit = new Command("Exit", Command.EXIT, 1); //exit = new Command("Exit", Command.SCREEN, 1); start = new Command("Start", Command.SCREEN, 1); f = new Form("Mixed Record"); f.addCommand(start); f.addCommand(exit); f.setCommandListener(this); }
  3. 3. public void startApp() { d.setCurrent(f); } public void pauseApp() { } public void destroyApp( boolean b ) { } public void commandAction(Command c, Displayable dd) { if (c == exit) { destroyApp(true); notifyDestroyed(); }
  4. 4. else if (c == start) { try { rec = RecordStore.openRecordStore("myRecordStore ", true ); } catch (Exception e) { /*a = new Alert("Error Creating", e.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a);*/ }
  5. 5. //String oS = "First Record"; String oS = "Rama Rao"; int oI = 15; boolean oB = true; //ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream ods = new DataOutputStream(baos); ods.writeUTF(oS); ods.writeBoolean(oB); ods.writeInt(oI); ods.flush(); by = baos.toByteArray();//copies from baos[] array into by array,it creates a newly byte[] array, and returns byte[] reference rec.addRecord(by, 0, by.length); baos.reset(); baos.close(); ods.close(); } catch ( Exception error) { /*a = new Alert("Error Writing",
  6. 6. try { String s = null; int i = 0; boolean b = false; byte[] by = new byte[100]; ByteArrayInputStream ist = new ByteArrayInputStream(by); //DataInputStream inputDataStream = DataInputStream ids = new DataInputStream(ist);
  7. 7. for (int x = 1; x <= rec.getNumRecords(); x++) { rec.getRecord(x, by, 0); s = ids.readUTF(); b = ids.readBoolean(); i = ids.readInt (); ist.reset(); }
  8. 8. ist.close(); ids.close(); a = new Alert("Reading", s + " " +i + " " + b, null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); //alert msg is not dissappear immediately d.setCurrent(a); } catch (Exception error) { /*a = new Alert("Error Reading", error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a);*/ } try { rec.closeRecordStore(); } catch (Exception error) { /*a = new Alert("Error Closing", error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a);*/
  9. 9. if (RecordStore.listRecordStores() != null) { try { RecordStore.deleteRecordStore("myRecordStor e"); } catch (Exception error) { /*a = new Alert("Error Removing", error.toString(), null, AlertType.WARNING); a.setTimeout(Alert.FOREVER); d.setCurrent(a);*/ } } } } }

×