Hi how to create a mobile book on j2me program, for example
dictionary, bible, magazine…. then read on the mobile phone,
tell me the code and steps or other help site. Thanks
Answer Posted / mohit chaudhry
package hello;
import javax.microedition.rms.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ReadWrite extends MIDlet implements CommandListener,RecordListener
{
private RecordStore rs = null;
RecordEnumeration re=null;
Display disp;
Alert a1,a2;
List l1,l2;
Form f,f1;
TextField tf,tf1;
Command edit,delete,back,go,ok;
public ReadWrite()
{
disp=Display.getDisplay(this);
a1=new Alert("Result");
a2=new Alert("Listener Result");
edit=new Command("Edit",Command.SCREEN,1);
delete=new Command("Delete",Command.SCREEN,2);
back=new Command("Back",Command.BACK,3);
ok=new Command("Ok",Command.OK,1);
go=new Command("Go",Command.OK,1);
l1=new List("Main Screen",List.IMPLICIT);
l2=new List("Contacts",List.IMPLICIT);
l1.append("Read", null);
l1.append("Write", null);
l1.append("Exit", null);
l1.addCommand(ok);
l2.addCommand(delete);
l2.addCommand(edit);
l2.addCommand(back);
l1.setCommandListener(this);
l2.setCommandListener(this);
f=new Form("Add Record");
tf=new TextField("Enter Data","",50,TextField.ANY);
f.append(tf);
f.addCommand(go);
f.setCommandListener(this);
try
{
rs = RecordStore.openRecordStore("data", true );
rs.addRecordListener(this);
}
catch (Exception e)
{ }
}
public void commandAction(Command c,Displayable d)
{
String s=l1.getString(l1.getSelectedIndex());
if(c==ok && s.equals("Read"))
{
l2.deleteAll();
try
{
re= rs.enumerateRecords(null, null, true);
while( re.hasNextElement() ){
byte[] data = re.nextRecord();
l2.append(new String(data), null);
}
disp.setCurrent(l2);
}
catch (Exception e)
{ }
}
if(c==ok && s.equals("Write"))
{
tf.setString(" ");
disp.setCurrent(f);
}
if(c==ok && s.equals("Exit"))
{
destroyApp(false);
notifyDestroyed();
try
{
rs.closeRecordStore();
RecordStore.deleteRecordStore("db");
}
catch (Exception e)
{ }
}
if(c==delete)
{
try
{
re = rs.enumerateRecords(null, null, true);
if (re.hasNextElement())
{
int recordId = re.nextRecordId();
rs.deleteRecord(recordId);
}
}
catch (Exception ex)
{ }
}
if(c==edit)
{
disp.setCurrent(f1);
}
if(c==back)
{
disp.setCurrent(l1);
}
if(c==go)
{
byte[] rec = tf.getString().getBytes();
try
{
rs.addRecord(rec, 0, rec.length);
tf.setString("");
}
catch (Exception e)
{ }
}
}
public void destroyApp( boolean unconditional )
{}
public void startApp()
{
disp.setCurrent(l1);
}
public void pauseApp()
{ }
public void recordAdded(RecordStore r,int rid)
{
a2.setString("record listener called for record add");
disp.setCurrent(a2,l1);
}
public void recordDeleted(RecordStore r,int rid)
{
a2.setString("record listener called for record delete");
disp.setCurrent(a2,l1);
}
public void recordChanged(RecordStore r,int rid)
{
a2.setString("record listener called for record chsnge");
disp.setCurrent(a2,l1);
}
}
| Is This Answer Correct ? | 12 Yes | 3 No |
Post New Answer View All Answers
Is there any framework in j2me that supports for all three HTc,iphone,Nokia phones.
Write a Java program to deactivate a cell phone when authentication failed
create a midp application,where user can enter player name and points.the program saves the information to the record using RMS at MIDP device.program should also print out the top 10 player list to the end user.
create a menu which has the following options:cut-can be on/off,copy-can be on/off,paste-can be on/off,delete-can be on/off,select all-put all4 options on,unselect all-put all 4 options off,using event handling in MIDP application
what is the use of wtk?
What is amps ?
Give the name of classes of j2se which is not used in j2me
In hyderabad, which s/w training center is best for java, other than corejava what r the new tools to learn in java,which tool is best & have current requirement,pls give me information about java to learn ?
what are all contain highlevel api?
11 is a group of specifications for wireless networks developed by the Institute of Electrical and Electronics Engineers (IEEE). 802.11 uses the Ethernet protocol and CSMA/CA (carrier sense multiple access with collision avoidance) for path sharing.
where images can be stored in j2me?
what is the application compatability?
What is j2me in mobile computing?
Memory managment technique in j2me
Memory managment technique in j2me