Tugas 5 Pemrograman Mobile - Mahendra

download Tugas 5 Pemrograman Mobile - Mahendra

of 14

Transcript of Tugas 5 Pemrograman Mobile - Mahendra

Pemrograman Mobile

RMS

(Record Managements System)

Oleh :I Putu Mahendra Pramadhitya (1104505027)Jurusan Teknologi Informasi

Fakultas Teknik

Universitas Udayana

2013RMS (record managements system) merupakan kombinasi antara file system dan database management system yang dapat kita gunakan untuk menyimpan data dalam bentuk baris dan kolom, sama dengan struktur data pada tabel dalam sebuah database. Berikut adalah Menampilkan Nama dengan menggunakan Text Field -> String Item dari Form 1 Kedalam Form 2 . berikut contohnya :1. Flow View Program

Masukan Back Command pada Form1 yang diman command back diperlukan untuk memgembalikan / back ke form sebelumnya . setelah itu click dan drag dari Form 1 ke Form seperti berikut :

Diperlukannya relasi dari OkCommand ( ke Form1 ) yang dimana bila kita menekan tombol OK pada applikasi Mobile tersebut maka dia akan masuk ke Form berikutnya dan sebaliknya BackCommand diperlukan untuk mengembalikan ke Form sebelumnya .

Terdapat 2 Form yang akan digunakan seperti yang diatas dan diisi command untuk OK , BACK , EXIT dari Form tersebut . Setelah itu masuk kedalam Form itu sendiri yang dimana seperti berikut :

2. Screen View Program

Form Input Data

Form Output Data

3. Kode program

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import javax.microedition.rms.*;

/**

* @author toshiba */

public class dataRMS extends MIDlet implements CommandListener {

private boolean midletPaused = false;

private RecordStore rs = null;

static final String REC_STORE = "ReadWriteRMS";

//

private Form form;

private TextField textField;

private Form form1;

private StringItem stringItem;

private Command backCommand;

private Command okCommand;

private Command backCommand1;

private Command exitCommand;

private Command backCommand2;

private Command backCommand3;

private Command exitCommand1;

private Command backCommand4;

private Command exitCommand2;

//

/**

* The dataRMS constructor.

*/

public dataRMS() {

}

//

//

//

/**

* Initializes the application. It is called only once when the MIDlet is

* started. The method is called before the

* startMIDlet method.

*/

private void initialize() {

// write pre-initialize user code here

// write post-initialize user code here

}

//

//

/**

* Performs an action assigned to the Mobile Device - MIDlet Started point.

*/

public void startMIDlet() {

// write pre-action user code here

switchDisplayable(null, getForm());

// write post-action user code here

}

//

//

/**

* Performs an action assigned to the Mobile Device - MIDlet Resumed point.

*/

public void resumeMIDlet() {

// write pre-action user code here

// write post-action user code here

}

//

//

/**

* Switches a current displayable in a display. The

* display instance is taken from

* getDisplay method. This method is used by all actions in the

* design for switching displayable.

*

* @param alert the Alert which is temporarily set to the display;

* if null, then nextDisplayable is set

* immediately

* @param nextDisplayable the Displayable to be set

*/

public void switchDisplayable(Alert alert, Displayable nextDisplayable) {

// write pre-switch user code here

Display display = getDisplay();

if (alert == null) {

display.setCurrent(nextDisplayable);

} else {

display.setCurrent(alert, nextDisplayable);

}

// write post-switch user code here

}

//

//

/**

* Called by a system to indicated that a command has been invoked on a

* particular displayable.

*

* @param command the Command that was invoked

* @param displayable the Displayable where the command was invoked

*/

public void commandAction(Command command, Displayable displayable) {

// write pre-action user code here

if (displayable == form) {

if (command == exitCommand2) {

// write pre-action user code here

exitMIDlet();

// write post-action user code here

} else if (command == okCommand) {

switchDisplayable(null, getForm1());

openRecord();

writeRecord(textField.getString());

readRecords();

}

} else if (displayable == form1) {

if (command == backCommand2) {

// write pre-action user code here

switchDisplayable(null, getForm());

// write post-action user code here

} else if (command == exitCommand) {

// write pre-action user code here

exitMIDlet();

// write post-action user code here

}

}

// write post-action user code here

}

//

//

/**

* Returns an initialized instance of form component.

*

* @return the initialized component instance

*/

public Form getForm() {

if (form == null) {

// write pre-init user code here

form = new Form("masukan data", new Item[]{getTextField()});

form.addCommand(getOkCommand());

form.addCommand(getExitCommand2());

form.setCommandListener(this);

// write post-init user code here

}

return form;

}

//

//

/**

* Returns an initialized instance of form1 component.

*

* @return the initialized component instance

*/

public Form getForm1() {

if (form1 == null) {

// write pre-init user code here

form1 = new Form("Hasil", new Item[]{getStringItem()});

form1.addCommand(getBackCommand2());

form1.addCommand(getExitCommand());

form1.setCommandListener(this);

// write post-init user code here

}

return form1;

}

//

//

/**

* Returns an initialized instance of backCommand component.

*

* @return the initialized component instance

*/

public Command getBackCommand() {

if (backCommand == null) {

// write pre-init user code here

backCommand = new Command("Back", Command.BACK, 0);

// write post-init user code here

}

return backCommand;

}

//

//

/**

* Returns an initialized instance of okCommand component.

*

* @return the initialized component instance

*/

public Command getOkCommand() {

if (okCommand == null) {

// write pre-init user code here

okCommand = new Command("Ok", Command.OK, 0);

// write post-init user code here

}

return okCommand;

}

//

//

/**

* Returns an initialized instance of backCommand1 component.

*

* @return the initialized component instance

*/

public Command getBackCommand1() {

if (backCommand1 == null) {

// write pre-init user code here

backCommand1 = new Command("Back", Command.BACK, 0);

// write post-init user code here

}

return backCommand1;

}

//

//

/**

* Returns an initialized instance of textField component.

*

* @return the initialized component instance

*/

public TextField getTextField() {

if (textField == null) {

// write pre-init user code here

textField = new TextField("Input Data", "", 32, TextField.ANY);

// write post-init user code here

}

return textField;

}

//

//

/**

* Returns an initialized instance of stringItem component.

*

* @return the initialized component instance

*/

public StringItem getStringItem() {

if (stringItem == null) {

// write pre-init user code here

stringItem = new StringItem("", "");

// write post-init user code here

}

return stringItem;

}

//

//

/**

* Returns an initialized instance of backCommand2 component.

*

* @return the initialized component instance

*/

public Command getBackCommand2() {

if (backCommand2 == null) {

// write pre-init user code here

backCommand2 = new Command("Back", Command.BACK, 0);

// write post-init user code here

}

return backCommand2;

}

//

//

/**

* Returns an initialized instance of exitCommand component.

*

* @return the initialized component instance

*/

public Command getExitCommand() {

if (exitCommand == null) {

// write pre-init user code here

exitCommand = new Command("Exit", Command.EXIT, 0);

// write post-init user code here

}

return exitCommand;

}

//

//

/**

* Returns an initialized instance of backCommand3 component.

*

* @return the initialized component instance

*/

public Command getBackCommand3() {

if (backCommand3 == null) {

// write pre-init user code here

backCommand3 = new Command("Back", Command.BACK, 0);

// write post-init user code here

}

return backCommand3;

}

//

//

/**

* Returns an initialized instance of exitCommand1 component.

*

* @return the initialized component instance

*/

public Command getExitCommand1() {

if (exitCommand1 == null) {

// write pre-init user code here

exitCommand1 = new Command("Exit", Command.EXIT, 0);

// write post-init user code here

}

return exitCommand1;

}

//

//

/**

* Returns an initialized instance of backCommand4 component.

*

* @return the initialized component instance

*/

public Command getBackCommand4() {

if (backCommand4 == null) {

// write pre-init user code here

backCommand4 = new Command("Back", Command.BACK, 0);

// write post-init user code here

}

return backCommand4;

}

//

//

/**

* Returns an initialized instance of exitCommand2 component.

*

* @return the initialized component instance

*/

public Command getExitCommand2() {

if (exitCommand2 == null) {

// write pre-init user code here

exitCommand2 = new Command("Exit", Command.EXIT, 0);

// write post-init user code here

}

return exitCommand2;

}

//

/**

* Returns a display instance.

*

* @return the display instance.

*/

public Display getDisplay() {

return Display.getDisplay(this);

}

/**

* Exits MIDlet.

*/

public void exitMIDlet() {

switchDisplayable(null, null);

destroyApp(true);

notifyDestroyed();

}

/**

* Called when MIDlet is started. Checks whether the MIDlet have been

* already started and initialize/starts or resumes the MIDlet.

*/

public void startApp() {

if (midletPaused) {

resumeMIDlet();

} else {

initialize();

startMIDlet();

}

midletPaused = false;

}

/**

* Called when MIDlet is paused.

*/

public void pauseApp() {

midletPaused = true;

}

/**

* Called to signal the MIDlet to terminate.

*

* @param unconditional if true, then the MIDlet has to be unconditionally

* terminated and all resources has to be released.

*/

public void destroyApp(boolean unconditional) {

}

public void openRecord() {

try {

rs = RecordStore.openRecordStore(REC_STORE, true);

}

catch (Exception e) {

System.out.println("Gagal");

}

}

public void writeRecord(String str) {

byte[] rec = str.getBytes();

try {

rs.addRecord(rec, 0, rec.length);

} catch (Exception e) {

}

}

public void readRecords() {

try {

byte[] recData = new byte[8];

int len;

for (int i = 1; i recData.length) {

recData = new byte[rs.getRecordSize(i)];

}

len = rs.getRecord(i, recData, 0);

String A = new String(recData, 0, len);

stringItem.setText(A);

}

}

catch (Exception e) {

}

}

private void writeRecord() {

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

}

}

4. Berikut adalah hasil running program proses input data dan output hasil :

Gambar 1. Input data

Gambar 2. Outuput Hasil