Good Luck...
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.util.*;
public class StoreMIDlet extends MIDlet implements CommandListener {
private static RecordStore rs;
private TextBox replyScreen,displayScreen;
private Form entryScreen;
private TextField in_name;
private List menu;
private String[] options = { "Login", "Profile"};
private Command cmdExit, cmdBack, cmdStore;
private StoreCanvas screen;
/**Construct the midlet*/
public StoreMIDlet() {
screen = new StoreCanvas();
}
/**Main method*/
public void startApp() {
try { //create store
//RecordStore.deleteRecordStore("SA");
rs = RecordStore.openRecordStore("Friends", true);
} catch (Exception e){
System.out.println("Error in opening Friends record store" + e);
}
//create menu implicit type
cmdExit= new Command("EXIT",Command.EXIT, 2 );
menu = new List("Select one to launch:",List.IMPLICIT,options,null);
menu.addCommand(cmdExit);
menu.setCommandListener(this);
// create entry screen
entryScreen = new Form("Login");
in_name = new TextField("Name :",null, 15,TextField.ANY);
entryScreen.append(in_name);
cmdStore = new Command("Save",Command.SCREEN, 2 );
cmdBack= new Command("Back",Command.STOP, 2 );
entryScreen.addCommand(cmdStore);
entryScreen.addCommand(cmdBack);
entryScreen.setCommandListener(this);
// create a reply screen
replyScreen= new TextBox("Login","",30,TextField.ANY);
replyScreen.addCommand(cmdBack);
replyScreen.setCommandListener(this);
displayScreen=new TextBox("Profile Page","",800,TextField.ANY);
displayScreen.addCommand(cmdBack);
displayScreen.setCommandListener(this);
Display.getDisplay(this).setCurrent(menu);
}
/**Handle pausing the MIDlet*/
public void pauseApp() {
}
/**Handle destroying the MIDlet*/
public void destroyApp(boolean unconditional) {
try {
rs.closeRecordStore();
} catch (Exception e){
System.out.println("Error in closing friend record store:" + e);
}
}
class StoreCanvas extends Canvas {
public void paint(Graphics g) {
int w = getWidth();
int h = getHeight();
//to add - clear screen by using the white color and fillRect()
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
//draw a big circle in the center
g.setColor(255,255,0);
g.drawArc(20,60,200,200,0,360);
//blue circle on the right
g.setColor(0,255,255);
g.fillArc(130,100,40,40,0,360);
//green circle in the center
g.setColor(0,255,0);
g.fillArc(105,160,40,25,0,360);
//left stroke down on the left of cross
g.setColor(0,0,0);
g.setStrokeStyle(Graphics.SOLID);
g.drawLine(70,105,105,140);
//right stroke down on the right of cross
g.setColor(0,0,0);
g.setStrokeStyle(Graphics.SOLID);
g.drawLine(105,105,70,140);
//to add - getFont()
g.setColor(255,0,0);
Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
//to add - retrieve name using drawstring()
g.drawString("Marcus", 125, 220, Graphics.BASELINEGraphics.HCENTER);
}
}
/** Handle command events*/
public void commandAction(Command c, Displayable d) {
int rid;
RecordEnumeration re = null;
byte[] data;
String show= new String ();
String data1 = new String();
String string1 = new String();
if(c==List.SELECT_COMMAND){
// System.out.println("Selected index:" + menu.getSelectedIndex());
switch(menu.getSelectedIndex()) {
case 0: Display.getDisplay(this).setCurrent(entryScreen);
break;
case 1: try {
re = rs.enumerateRecords(null,null,false);
while(re.hasNextElement()){
data1 = new String(re.nextRecord());
show+="Record is " + data1;
show=show + "\n";
System.out.println(show);
}
displayScreen.setString(show);
}catch (Exception e){
System.out.println("Error in traversing Friends record store" + e);
}
Display.getDisplay(this).setCurrent(screen);
break;
default : replyScreen.setString("Store operation Not selected");
}// end Switch
}
if(c==cmdStore){
try { string1 = in_name.getString();
rid = rs.addRecord(string1.getBytes(), 0, string1.length());
System.out.println("Record:" + rid + " is added");
} catch (Exception e){
System.out.println("Error in adding friend:" + e);
}
replyScreen.setString(in_name.getString()+ " has been added");
Display.getDisplay(this).setCurrent(replyScreen);
}
if(c.getCommandType() == Command.EXIT){
destroyApp(true);
notifyDestroyed();
}
if(c==cmdBack && d == replyScreen){
Display.getDisplay(this).setCurrent(entryScreen);
}
if(c==cmdBack && d == entryScreen){
Display.getDisplay(this).setCurrent(menu);
}
if(c==cmdBack && d == displayScreen){
Display.getDisplay(this).setCurrent(menu);
}
}
}
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.util.*;
public class StoreMIDlet extends MIDlet implements CommandListener {
private static RecordStore rs;
private TextBox replyScreen,displayScreen;
private Form entryScreen;
private TextField in_name;
private List menu;
private String[] options = { "Login", "Profile"};
private Command cmdExit, cmdBack, cmdStore;
private StoreCanvas screen;
/**Construct the midlet*/
public StoreMIDlet() {
screen = new StoreCanvas();
}
/**Main method*/
public void startApp() {
try { //create store
//RecordStore.deleteRecordStore("SA");
rs = RecordStore.openRecordStore("Friends", true);
} catch (Exception e){
System.out.println("Error in opening Friends record store" + e);
}
//create menu implicit type
cmdExit= new Command("EXIT",Command.EXIT, 2 );
menu = new List("Select one to launch:",List.IMPLICIT,options,null);
menu.addCommand(cmdExit);
menu.setCommandListener(this);
// create entry screen
entryScreen = new Form("Login");
in_name = new TextField("Name :",null, 15,TextField.ANY);
entryScreen.append(in_name);
cmdStore = new Command("Save",Command.SCREEN, 2 );
cmdBack= new Command("Back",Command.STOP, 2 );
entryScreen.addCommand(cmdStore);
entryScreen.addCommand(cmdBack);
entryScreen.setCommandListener(this);
// create a reply screen
replyScreen= new TextBox("Login","",30,TextField.ANY);
replyScreen.addCommand(cmdBack);
replyScreen.setCommandListener(this);
displayScreen=new TextBox("Profile Page","",800,TextField.ANY);
displayScreen.addCommand(cmdBack);
displayScreen.setCommandListener(this);
Display.getDisplay(this).setCurrent(menu);
}
/**Handle pausing the MIDlet*/
public void pauseApp() {
}
/**Handle destroying the MIDlet*/
public void destroyApp(boolean unconditional) {
try {
rs.closeRecordStore();
} catch (Exception e){
System.out.println("Error in closing friend record store:" + e);
}
}
class StoreCanvas extends Canvas {
public void paint(Graphics g) {
int w = getWidth();
int h = getHeight();
//to add - clear screen by using the white color and fillRect()
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
//draw a big circle in the center
g.setColor(255,255,0);
g.drawArc(20,60,200,200,0,360);
//blue circle on the right
g.setColor(0,255,255);
g.fillArc(130,100,40,40,0,360);
//green circle in the center
g.setColor(0,255,0);
g.fillArc(105,160,40,25,0,360);
//left stroke down on the left of cross
g.setColor(0,0,0);
g.setStrokeStyle(Graphics.SOLID);
g.drawLine(70,105,105,140);
//right stroke down on the right of cross
g.setColor(0,0,0);
g.setStrokeStyle(Graphics.SOLID);
g.drawLine(105,105,70,140);
//to add - getFont()
g.setColor(255,0,0);
Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
//to add - retrieve name using drawstring()
g.drawString("Marcus", 125, 220, Graphics.BASELINEGraphics.HCENTER);
}
}
/** Handle command events*/
public void commandAction(Command c, Displayable d) {
int rid;
RecordEnumeration re = null;
byte[] data;
String show= new String ();
String data1 = new String();
String string1 = new String();
if(c==List.SELECT_COMMAND){
// System.out.println("Selected index:" + menu.getSelectedIndex());
switch(menu.getSelectedIndex()) {
case 0: Display.getDisplay(this).setCurrent(entryScreen);
break;
case 1: try {
re = rs.enumerateRecords(null,null,false);
while(re.hasNextElement()){
data1 = new String(re.nextRecord());
show+="Record is " + data1;
show=show + "\n";
System.out.println(show);
}
displayScreen.setString(show);
}catch (Exception e){
System.out.println("Error in traversing Friends record store" + e);
}
Display.getDisplay(this).setCurrent(screen);
break;
default : replyScreen.setString("Store operation Not selected");
}// end Switch
}
if(c==cmdStore){
try { string1 = in_name.getString();
rid = rs.addRecord(string1.getBytes(), 0, string1.length());
System.out.println("Record:" + rid + " is added");
} catch (Exception e){
System.out.println("Error in adding friend:" + e);
}
replyScreen.setString(in_name.getString()+ " has been added");
Display.getDisplay(this).setCurrent(replyScreen);
}
if(c.getCommandType() == Command.EXIT){
destroyApp(true);
notifyDestroyed();
}
if(c==cmdBack && d == replyScreen){
Display.getDisplay(this).setCurrent(entryScreen);
}
if(c==cmdBack && d == entryScreen){
Display.getDisplay(this).setCurrent(menu);
}
if(c==cmdBack && d == displayScreen){
Display.getDisplay(this).setCurrent(menu);
}
}
}