Chris Pollett > Students >
Rekha

    ( Print View )

    [Bio]

    [CS297Proposal]

    [Del1]

    [Del2]

    [Del3]

    [Del4]

    [CS297 Report-PDF]

    [CS298 Proposal]

    [CS298 Presentation-PDF]

    [Game Description-PDF]

    [Final Game-ZIP]

    [CS298 Report-PDF]

                          

























A GUI for entering the business card information and using J2ME's RMS(Record Management System) for retrieving it

Description: This deliverable introduced me to J2ME's GUI and RMS(Record Management System) concepts. In this deliverable, user will be presented with a menu with the options--"Enter Info" and "List". If the user selects the Enter Info option, he can enter the business card information like First Name, Last Name, Phone Number, Email ID. And then he can submit the information. If he selects the "List" option, he can get the list of all the information that has been stored.

Example:This is what my code outputs on these inputs.

The initial menu

Example:This is what my code outputs on these inputs.

The GUI to type in the information

Example:This is what my code outputs on these inputs.

The list of the information stored

The user is presented with the menu as shown in first screenshot and he chooses the Enter Info option and entered the information in the fields shown in the second screenshot and later is presented with the same menu where he chooses list option with which the information is displayed as shown in the third screenshot.

/**
  @author Rekha Vaddepalli
  This is the first deliverable of CS  297 to use the functionality of MIDP
  GUI and the Record Management System (RMS) to get and store the business card
  information of people

 */
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.io.*;


public class BusinessCardInfo extends MIDlet
                              implements CommandListener
{
  private Display display;
  private Form form;
  private Form form2 = new Form("Enter Info");;

  private Command getInfo;
  private Command submit;
  private Command list;
  private Command exit;

  private TextField tfFirstName;
  private TextField tfLastName;
  private TextField tfPhoneNumber;
  private TextField tfEmailID;

  private RecordStore recordstore = null;
  private RecordEnumeration recordEnum = null;

  private Alert alert;

/**
   It is the class that holds the first name, last name, phone number, email ID
 */
  private static class Businesscard {
	public String firstname;
	public String lastname;
	public String phonenumber;
	public String email;

   }

  Businesscard record = new Businesscard();

/**
   Method BusinessCardInfo.
   It is the constructor for the class
 */
  public BusinessCardInfo()
  {
   display = Display.getDisplay(this);

   getInfo = new Command("Enter Info",Command.SCREEN, 1);
   list = new Command("List", Command.SCREEN, 2);
   exit = new Command("Exit", Command.EXIT, 1);

   form = new Form("Business Card Information");

   form.addCommand(exit);
   form.addCommand(list);
   form.addCommand(getInfo);
   form.setCommandListener(this);

  }

/**
   Method startApp.
   It is the method to be implemented for the midlet instantiation
 */
  public void startApp()
  {
	display.setCurrent(form);
  }

/**
   Method pauseApp.
   It is the method to be implemted for the midlet
 */
  public void pauseApp()
  {
  }

/**
   Method destroyApp.
   @param unconditional
   This is the method that tells what to do before destroying the application.
   If any recordstores are still present in the system, remove them

 */
  public void destroyApp(boolean unconditional)
  {
	if(RecordStore.listRecordStores() != null){
	try{
          RecordStore.deleteRecordStore("myRecordStore7");
	  recordEnum.destroy();
	}catch(Exception error){
	alert = new Alert("Error Removing",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);
	}
	}
  }

/**
   Method commandAction.
   @param command
   @param displayable

   It is the method in which the command actions for the different command buttons
   are defined.
   When the command button is getInfo, it shows the screen to enter the information
   When the command button is submit, it enters the information entered into the record store
   When the command button is list, it lists the information stored in the Record store
   When the command button is exit, the application exits

 */
  public void commandAction(Command command, Displayable displayable)
  {
   if (command == getInfo)
   {
	submit = new Command("Submit", Command.SCREEN, 1);
	tfFirstName = new TextField("First Name:", "", 30, TextField.ANY);
	tfLastName = new TextField("Last Name:", "", 30, TextField.ANY);
	tfPhoneNumber = new TextField("Phone Number:", "", 30, TextField.PHONENUMBER);
	tfEmailID = new TextField("Email ID:", "", 30, TextField.EMAILADDR);

	form2 = new Form("Type the Information");
	form2.addCommand(submit);
	form2.append(tfFirstName);
	form2.append(tfLastName);
	form2.append(tfPhoneNumber);
	form2.append(tfEmailID);
	form2.setCommandListener(this);

	display.setCurrent(form2);
   }
   else if (command == submit)
   {

	try{

	recordstore = RecordStore.openRecordStore("myRecordStore7",true);

	}catch(Exception error){

	alert = new Alert("Error Creating",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);

	}

 	try{

	byte[] outputRecord;

	record.firstname = tfFirstName.getString();
	record.lastname = tfLastName.getString();
	record.phonenumber = tfPhoneNumber.getString();
	record.email = tfEmailID.getString();

	System.out.println(record.firstname+" "+record.lastname+" "+record.phonenumber+" 	"+record.email);

	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	DataOutputStream outputDataStream = new DataOutputStream(outputStream);

    outputDataStream.writeUTF(record.firstname);
	outputDataStream.writeUTF(record.lastname);
	outputDataStream.writeUTF(record.phonenumber);
	outputDataStream.writeUTF(record.email);

	outputDataStream.flush();

    outputRecord = outputStream.toByteArray();
	recordstore.addRecord(outputRecord,0,outputRecord.length);


	outputStream.reset();
	outputStream.close();
	outputDataStream.close();

	}catch(Exception error){

	alert = new Alert("Error Writing",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);

	}
 	try{
	recordstore.closeRecordStore();
	}catch(Exception error){
	alert = new Alert("Error Closing",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);

	}

	display.setCurrent(form);
  }

   else if (command == list)
   {

	try{


	recordstore = RecordStore.openRecordStore("myRecordStore7",true);

	}catch(Exception error){

	alert = new Alert("Error Creating in List",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);

	}

	try{

	String inFirstName = null;
	String inLastName = null;
	String inPhoneNumber = null;
	String inEmailID = null;

	StringBuffer buffer = new StringBuffer();
	byte[] byteInputData = new byte[300];
	ByteArrayInputStream inputStream = null;

	DataInputStream inputDataStream = null;


	recordEnum = recordstore.enumerateRecords(null,null,false);
	System.out.println("No of records "+recordstore.getNumRecords());

	while(recordEnum.hasNextElement()){

	byteInputData = recordEnum.nextRecord();
	inputStream = new ByteArrayInputStream(byteInputData);
	inputDataStream = new DataInputStream(inputStream);

		buffer.append("First Name:");
		buffer.append(inputDataStream.readUTF());
		buffer.append("\n");
		buffer.append("Last Name:");
		buffer.append(inputDataStream.readUTF());
		buffer.append("\n");
		buffer.append("Phone Number:");
		buffer.append(inputDataStream.readUTF());
		buffer.append("\n");
		buffer.append("Email:");
		buffer.append(inputDataStream.readUTF());
		buffer.append("\n");
		buffer.append("-------------\n");

		System.out.println(buffer.toString());



	}
	alert = new Alert("Reading",buffer.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);
	inputStream.close();
	inputDataStream.close();

	}catch(Exception error){
	alert = new Alert("Error Reading",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);

	}

 	try{
	recordstore.closeRecordStore();
	}catch(Exception error){
	alert = new Alert("Error Closing",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);

	}

   }

   else if (command == exit)
   {

  if(RecordStore.listRecordStores() != null){
	try{
          RecordStore.deleteRecordStore("myRecordStore3");
		  recordEnum.destroy();
	}catch(Exception error){
	alert = new Alert("Error Removing",error.toString(),null,AlertType.WARNING);
	alert.setTimeout(Alert.FOREVER);
	display.setCurrent(alert);

	}
	}
    destroyApp(false);
    notifyDestroyed();
   }
  }
}