• Tidak ada hasil yang ditemukan

BAB II TINJAUAN PUSTAKA

6.2. Saran

Berdasarkan pengalaman dalam proses pembuatan aplikasi ini, terdapat beberapa saran yang diusulkan oleh penyusun terkait untuk pengembangan aplikasi lebih lanjut. Saran-saran tersebut antara lain: Untuk pengembangan lebih lanjut, aplikasi ini dapat di kembangkan lagi dari segi desain agar lebih banyak menggunakan gambar. Untuk memperbanyak latihan dalam meng-coding agar lebih cepat dalam melakukan proses membuat program. Menambah jenis tanaman yang ada di dalam system, agar informasi yang dibutuhkan oleh pengguna lebih lengkap.

DAFTAR PUSTAKA

Muhlisah, Fauziah.2008.Tanaman Obat Keluarga (Toga).Penebar Swadaya.Jakarta M. Shalahuddin. 2008. Pemrograman J2ME. Informatika. Bandung

Nugroho, Adi.2009.Rekayasa Perangkat Lunak Menggunakan UML dan JAVA. Andi. Yogyakarta.

Raharjo, Budi & Heryanto, Imam. 2007. Tuntunan Pemrograman Java untuk Handphone. Informatika. Bandung

Siregar, Ivan. 2007. Membangun Aplikasi Chat Lewat GPRS Dengan Menggunakan NetBeans IDE 5.0. Gava Media. Bandung

Winarto,W.P.2007.Mahkota dewa:budi daya & pemanfaatan untuk obat.Penebar swadaya.Jakarta

Winarto,W.P.2005.Daun dewa:budi daya & pemanfaatan untuk obat.Penebar swadaya.Jakarta

LAMPIRAN

Source Code Aplikasi

Home.java :

/*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import java.io.IOException; import java.util.Vector; 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.lcdui.TextField; import javax.microedition.midlet.*; /** * @author Ulum */

public class Home extends MIDlet implements CommandListener { private StringItem result = new StringItem(null, "Aplikasi Ini dibuat untuk membantu pengguna dalam mengetahui informasi tanaman toga");

private String[] options = {"Tanaman Toga", "Admin Toga", "Pencarian Penyakit", "Petunjuk Penggunaan"};

private String[] nameImage = {Network_32_resize.png", "Sys-NetService_32_resize.png", "icon-search_32_resize.png",

"Doc-Image_32_resize.png"};

private String[] actTanaman = {"ADD Tanaman", "Update / Delete Tanaman"};

private String[] actGuna = {"Add Kegunaan", "Update / Delete Kegunaan"};

private int[][] mappingLogin = {{1, 0, 1, 1}, {1, 1, 1, 1}}; private static final String[][] loginPass = {{"admin", "admin"}}; private List menu;

private List lActTanaman; private List lActGuna;

private List lActTanamandDleteUpdate; private List tanamanList;

private List gunaList; private List srcgunaList; private Form frmKeterangan; private Form frmDetail; private Form resultDetail; private Form frmLogin; private TogaDB togaDB; private GunaDB gunaDB; private Form frmSearch;

private NamaKegunaan namaKegunaan; private Display display;

private Vector tanamans; private Vector gunas;

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

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

private Command updateCommand = new Command("Update", Command.OK, 1);

private Command deleteCommand = new Command("Delete", Command.OK, 1);

private Command addCommand = new Command("Add", Command.OK, 1); private Command detailCommand = new Command("Detail", Command.OK, 1);

private Command viewDetailCommand = new Command("View Detail", Command.OK, 1);

private Command searchCommand = new Command("Search", Command.OK, 1);

private Command loginCommand = new Command("Login", Command.OK, 1);

private Command logoutCommand = new Command("Logout", Command.BACK, 1);

private int fromActTanaman = 0; private int FROM_VIEW_DETAIL = 0; private int FROM_ADMIN_DETAIL = 1; private int idTanaman = 0;

private int statusUser = 0; public Home() {

Image[] nimg = new Image[nameImage.length]; for(int i=0;i<nimg.length;i++){

try {

nimg[i] = Image.createImage("/" + nameImage[i]); } catch (IOException ex) {

ex.printStackTrace(); }

}

menu = new List("Main Menu Tanaman Toga", List.IMPLICIT, options, nimg);

menu.addCommand(exitCommand); menu.setCommandListener(this);

// display.setCurrent(menu); togaDB = new TogaDB();

gunaDB = new GunaDB();

display = Display.getDisplay(this); }

public void commandAction(Command c, Displayable d) { if (d == menu && c == List.SELECT_COMMAND) { if

(menu.getString(menu.getSelectedIndex()).equals(options[0])) { tanamans = togaDB.retrieveAll();

if (tanamans.size() == 0) {

Alert emptyInfo = new Alert("Data Tanaman Kosong", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER);

emptyInfo.setString("Tanaman Kosong\n Isi data Tanaman terlebih dahulu");

} else {

fromActTanaman = FROM_VIEW_DETAIL; tanamanList = new List("List Tanaman", List.IMPLICIT);

tanamanList.addCommand(backCommand); tanamanList.addCommand(viewDetailCommand); tanamanList.setCommandListener(this);

for (int i = 0; i < tanamans.size(); i++) { Tanaman app = (Tanaman)

tanamans.elementAt(i); tanamanList.append(app.getNama(), null); } display.setCurrent(tanamanList); } } else if (menu.getString(menu.getSelectedIndex()).equals(options[1])) { if (statusUser == 0) {

frmLogin = new Form("Login Form");

frmLogin.append(new TextField("Username", "", 255, TextField.ANY)); frmLogin.append(new TextField("Password", "", 255, TextField.PASSWORD)); frmLogin.addCommand(backCommand); frmLogin.addCommand(loginCommand); frmLogin.setCommandListener(this); display.setCurrent(frmLogin); } else {

lActTanaman = new List("Admin Tanaman", List.IMPLICIT, actTanaman, null);

lActTanaman.addCommand(backCommand); lActTanaman.addCommand(logoutCommand); lActTanaman.setCommandListener(this); display.setCurrent(lActTanaman); } } else if (menu.getString(menu.getSelectedIndex()).equals(options[2])) { frmSearch.append(new TextField("Nama Penyakit", "", 64, TextField.ANY)); frmSearch.addCommand(backCommand); frmSearch.addCommand(searchCommand); frmSearch.setCommandListener(this); display.setCurrent(frmSearch); } else if (menu.getString(menu.getSelectedIndex()).equals(options[3])) { frmKeterangan = new Form("Petunjuk Penggunaan"); frmKeterangan.addCommand(backCommand);

frmKeterangan.setCommandListener(this); display.setCurrent(frmKeterangan); }

} else if (d == menu && c == exitCommand) { destroyApp(true); notifyDestroyed(); // display.setCurrent(frmLogin); } else if (d == lActTanaman) { if (c == List.SELECT_COMMAND) { switch (lActTanaman.getSelectedIndex()) { case 0:

namaTanaman = new NamaTanaman(display, lActTanaman, togaDB);

display.setCurrent(namaTanaman); break;

case 1:

tanamans = togaDB.retrieveAll(); if (tanamans.size() == 0) {

Alert emptyInfo = new Alert("Data Tanaman Kosong", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER); emptyInfo.setString("Tanaman Kosong\n Isi data Tanaman terlebih dahulu");

display.setCurrent(emptyInfo, lActTanaman);

} else {

tanamanList = new List("Update / Delete Tanaman", List.IMPLICIT); tanamanList.addCommand(backCommand); tanamanList.addCommand(updateCommand); tanamanList.addCommand(deleteCommand); tanamanList.addCommand(detailCommand); tanamanList.setCommandListener(this); for (int i = 0; i < tanamans.size(); i++) {

Tanaman app = (Tanaman) tanamans.elementAt(i); tanamanList.append(app.getNama(), null); } display.setCurrent(tanamanList); } break; default: break; } } else if (c == backCommand) { display.setCurrent(menu); } else if (c == logoutCommand) { statusUser = 0; display.setCurrent(menu); } } else if (d == tanamanList) { if (c == backCommand) { if (fromActTanaman == FROM_VIEW_DETAIL) { display.setCurrent(menu);

} else if (fromActTanaman == FROM_ADMIN_DETAIL) { display.setCurrent(lActTanaman);

}

} else if (c == deleteCommand) {

int index = tanamanList.getSelectedIndex(); if (index >= 0) {

Tanaman tanaman = (Tanaman) tanamans.elementAt(index);

Alert emptyInfo = new Alert("Delete Item", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER); int tempTanaman = tanaman.getId(); if (togaDB.delete(tanaman)) { Vector vTemp =

gunaDB.retrieveByTanaman(tempTanaman);

for (int i = 0; i < vTemp.size(); i++) { gunaDB.delete((Guna) vTemp.elementAt(i)); }

tanamans = togaDB.retrieveAll();

for (int i = 0; i < tanamans.size(); i++) { Tanaman app = (Tanaman)

tanamans.elementAt(i); tanamanList.append(app.getNama(), null); } emptyInfo.setString("Success"); } else { emptyInfo.setString("Failed"); } display.setCurrent(emptyInfo, tanamanList); } else {

Alert emptyInfo = new Alert("Un Selected Item", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER);

emptyInfo.setString("Pilihlah Salah Satu Item untuk Dihapus");

display.setCurrent(emptyInfo, tanamanList); }

} else if (c == updateCommand) {

int index = tanamanList.getSelectedIndex(); if (index >= 0) {

Tanaman tanaman = (Tanaman) tanamans.elementAt(index);

namaTanaman = new NamaTanaman(display, tanamanList, togaDB, tanaman);

display.setCurrent(namaTanaman); } else {

Alert emptyInfo = new Alert("Un Selected Item", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER);

emptyInfo.setString("Pilihlah Salah Satu Item untuk Dihapus");

display.setCurrent(emptyInfo, tanamanList); }

} else if (c == detailCommand) {

int index = tanamanList.getSelectedIndex(); if (index >= 0) {

fromActTanaman = FROM_ADMIN_DETAIL; Tanaman tanaman = (Tanaman)

tanamans.elementAt(index); gunas =

gunaDB.retrieveByTanaman(tanaman.getId());

gunaList = new List("Update / Delete Kegunaan Tanaman", List.IMPLICIT);

gunaList.addCommand(backCommand); gunaList.addCommand(addCommand); gunaList.setCommandListener(this); for (int i = 0; i < gunas.size(); i++) { Guna app = (Guna) gunas.elementAt(i); gunaList.append(app.getNama(), null); }

idTanaman = tanaman.getId(); display.setCurrent(gunaList); } else {

Alert emptyInfo = new Alert("Un Selected Item", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER);

emptyInfo.setString("Pilihlah Salah Satu Item untuk Dihapus");

}

} else if (c == viewDetailCommand) { Tanaman tanaman = (Tanaman)

tanamans.elementAt(tanamanList.getSelectedIndex()); frmDetail = new Form(tanaman.getNama()); StringItem resultField = new StringItem(null, tanaman.getInfo()); frmDetail.append(resultField); frmDetail.setCommandListener(this); display.setCurrent(frmDetail); } } else if (d == gunaList) { if (c == addCommand) {

namaKegunaan = new NamaKegunaan(display, gunaList, gunaDB, idTanaman);

display.setCurrent(namaKegunaan); } else if (c == updateCommand) {

int index = tanamanList.getSelectedIndex(); if (index >= 0) {

Guna guna = (Guna) gunas.elementAt(index); namaKegunaan = new NamaKegunaan(display, gunaList, gunaDB, guna);

display.setCurrent(namaKegunaan); } else {

Alert emptyInfo = new Alert("Un Selected Item", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER);

emptyInfo.setString("Pilihlah Salah Satu Item untuk Dihapus");

display.setCurrent(emptyInfo, tanamanList); }

} else if (c == deleteCommand) {

int index = tanamanList.getSelectedIndex(); if (index >= 0) {

Guna guna = (Guna) gunas.elementAt(index); int tempTanaman = guna.getTanamanId();

Alert emptyInfo = new Alert("Delete Item", "", null, AlertType.INFO); emptyInfo.setTimeout(Alert.FOREVER); if (gunaDB.delete(guna)) { gunaList.deleteAll(); gunas = gunaDB.retrieveByTanaman(tempTanaman);

for (int i = 0; i < gunas.size(); i++) { Guna app = (Guna) gunas.elementAt(i); gunaList.append(app.getNama(), null); } emptyInfo.setString("Success"); } else { emptyInfo.setString("Failed"); } display.setCurrent(emptyInfo, gunaList); } else {

Alert emptyInfo = new Alert("Un Selected Item", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER);

emptyInfo.setString("Pilihlah Salah Satu Item untuk Dihapus");

display.setCurrent(emptyInfo, gunaList); }

display.setCurrent(tanamanList); } } else if (d == frmDetail) { if (c == backCommand) { display.setCurrent(tanamanList); } } else if (d == frmSearch) { if (c == backCommand) { display.setCurrent(menu); } else if (c == searchCommand) { String src = ((TextField) frmSearch.get(0)).getString(); srcgunas = gunaDB.retrieveByPenyakit(src);

srcgunaList = new List("Search Obat", List.IMPLICIT); srcgunaList.addCommand(backCommand);

srcgunaList.addCommand(viewDetailCommand); srcgunaList.setCommandListener(this);

for (int i = 0; i < srcgunas.size(); i++) { Guna app = (Guna) srcgunas.elementAt(i); Tanaman tanaman = (Tanaman)

togaDB.getById(app.getTanamanId()); srcgunaList.append(tanaman.getNama(), null); } display.setCurrent(srcgunaList); } } else if (d == srcgunaList) { if (c == backCommand) { display.setCurrent(frmSearch); } else if (c == viewDetailCommand) {

int index = srcgunaList.getSelectedIndex();

String namaTanaman = srcgunaList.getString(index); Guna guna = (Guna) srcgunas.elementAt(index)

sb.append("Nama Penyakit:\n"); sb.append(guna.getNama());

sb.append("\nCara Pengobatan :\n"); sb.append(guna.getCara());

StringItem result = new StringItem(null, sb.toString()); resultDetail.append(result); resultDetail.addCommand(backCommand); resultDetail.setCommandListener(this); } } else if (d == resultDetail) { if (c == backCommand) { display.setCurrent(srcgunaList); } } else if (d == frmKeterangan) { if (c == backCommand) { display.setCurrent(menu); } } else if (d == frmLogin) { if (c == loginCommand) {

String uname = ((TextField) frmLogin.get(0)).getString();

String pass = ((TextField) frmLogin.get(0)).getString();

if (uname.length() == 0 || pass.length() == 0) { Alert emptyInfo = new Alert("Empty Parameter", "", null, AlertType.INFO);

emptyInfo.setString("Isi Parameter Username dan Password");

display.setCurrent(emptyInfo, frmLogin); } else {

boolean flag = true;

Vector nVectors = new Vector();

for (int i = 0; i < loginPass.length; i++) { if (uname.equals(loginPass[i][0]) && pass.equals(loginPass[i][1])) { statusUser = 1; break; } } if (statusUser == 0) {

Alert emptyInfo = new Alert("Wrong Username Password", "", null, AlertType.INFO);

emptyInfo.setTimeout(Alert.FOREVER);

emptyInfo.setString("Isi Parameter Username dan Password dengan benar");

display.setCurrent(emptyInfo, frmLogin); } else {

lActTanaman = new List("Admin Tanaman", List.IMPLICIT, actTanaman, null);

lActTanaman.addCommand(logoutCommand); lActTanaman.addCommand(backCommand); lActTanaman.setCommandListener(this); display.setCurrent(lActTanaman); } } } else if (c == backCommand) { display.setCurrent(menu); } } }

public void startApp() { display.setCurrent(menu); }

public void pauseApp() { }

public void destroyApp(boolean unconditional) { gunaDB.close(); togaDB.close(); menu = null; } } TogaDB.java: /*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import java.util.Vector; import javax.microedition.rms.RecordComparator; import javax.microedition.rms.RecordFilter; import javax.microedition.rms.RecordStore;

/** *

* @author Ulum */

public class TogaDB { RecordStore rs = null; public TogaDB() {

String file = "togaDB"; try { rs = RecordStore.openRecordStore(file, true); } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } }

public void close() { if (rs != null) { try { rs.closeRecordStore(); } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } } }

public boolean delete(Tanaman app) { boolean success = false;

int id = app.getId(); if (id == 0) { return false; } try { rs.deleteRecord(id); success = true; } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } return success; }

public Tanaman getById(int id) { Tanaman app = null;

try {

byte data[] = rs.getRecord(id); app = new Tanaman(id, data); } catch (Exception e) {

System.out.println("Error : " + e.getMessage()); }

return app; }

public Vector retrieveAll() { RecordEnumeration re = null; Vector apps = new Vector(); try {

re = rs.enumerateRecords(null, null, true);// enumerateRecords(rf, rc, true);

int rec_id = re.nextRecordId(); apps.addElement(new Tanaman(rec_id, rs.getRecord(rec_id))); } } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } finally { if (re != null) { re.destroy(); } } return apps; }

public boolean save(Tanaman app) { if (rs == null) {

return false; }

boolean success = false; try {

byte[] data = app.toBytes(); int id = app.getId();

if (id == 0) {

id = rs.addRecord(data, 0, data.length); app.setId(id);

} else {

rs.setRecord(id, data, 0, data.length); } success = true; } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } return success; } } GunaFilterPenyakit.java: /*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import javax.microedition.rms.RecordFilter; /** * * @author Ulum */

public class GunaFilterPenyakit implements RecordFilter{ private String src;

public GunaFilterPenyakit(String src){ this.src=src.trim().toLowerCase(); }

public boolean matches(byte[] candidate){ Guna app = new Guna();

app.init_app(candidate);

String cur = app.getNama().toLowerCase(); if(cur.indexOf(src)>=0){

return true; }else{ return false; } } } GunaFilterTanaman.java: /*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import javax.microedition.rms.RecordFilter; /** * * @author Ulum */

public class GunaFilterTanaman implements RecordFilter{ private int idTanaman;

public GunaFilterTanaman(int idTanaman){ this.idTanaman=idTanaman;

}

public boolean matches(byte[] candidate){ Guna app = new Guna();

app.init_app(candidate); if(app.getTanamanId()==idTanaman){ return true; }else{ return false; } } } Tanaman.java: /*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.util.Vector; /** * * @author Ulum */

public class Tanaman { private int id; private String nama; private String info;

private Vector listGuna; public Tanaman(){ id=0; nama=""; info=""; listGuna=new Vector(); }

public Tanaman(int id,byte[] rec){ this.id=id;

init_app(rec); }

public Tanaman(int id,String nama,String info){ this.id=id;

this.nama=nama; this.info=info; }

public void init_app(byte[] rec){

ByteArrayInputStream bais = new ByteArrayInputStream(rec); DataInputStream dis = new DataInputStream(bais);

try { nama=dis.readUTF(); info = dis.readUTF(); } catch (Exception e) { } }

public byte[] toBytes(){ byte[] data = null; try {

ByteArrayOutputStream baos = new ByteArrayOutputStream(); dos.writeUTF(info); data=baos.toByteArray(); baos.close(); dos.close(); } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } return data; }

public int getId(){return this.id;} public void setId(int id){this.id=id;} public String getNama(){return this.nama;}

public void setNama(String nama){this.nama=nama;} public String getInfo(){return this.info;}

public void setInfo(String info){this.info=info;} }

NamaTanaman.java :

/*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.List; import javax.microedition.lcdui.TextBox; import javax.microedition.lcdui.TextField; /** * * @author Ulum */

public class NamaTanaman extends TextBox implements CommandListener { private Tanaman tanaman;

private String nama=""; public List home;

private Display display;

private Command nextCommand = new Command("Next",Command.OK,1); private Command cancelCommand = new

Command("Cancel",Command.CANCEL,1);

private DeskripsiTanaman deskripsiTanaman; public TogaDB togaDB;

public NamaTanaman(Display display,List home,TogaDB togaDB){ super("Nama Tanaman","",64,TextField.ANY);

System.out.println(home.getString(0)); this.togaDB=togaDB;

this.display=display; this.home=home;

tanaman = new Tanaman(); init_app();

}

public NamaTanaman(Display display,List home,TogaDB togaDB,Tanaman tanaman){ super("Nama Tanaman",tanaman.getNama(),65536,TextField.ANY); this.togaDB=togaDB; this.home=home; this.display=display; this.tanaman=tanaman; init_app(); }

private void init_app(){ addCommand(nextCommand); addCommand(cancelCommand); setCommandListener(this); }

public void commandAction(Command c,Displayable d){ if(c==nextCommand){

this.nama=getString(); if(tanaman.getId()==0){

deskripsiTanaman = new DeskripsiTanaman(display, this, nama);

}else{

deskripsiTanaman = new DeskripsiTanaman(display, this, nama,tanaman); } display.setCurrent(deskripsiTanaman); }else if(c==cancelCommand){ display.setCurrent(home); } } } DeskripsiTanaman.java : /*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import java.util.Vector; 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.TextBox; import javax.microedition.lcdui.TextField; /** * * @author Ulum */

public class DeskripsiTanaman extends TextBox implements CommandListener {

private int id=0;

private String nama="";

private Command saveCommand = new Command("Save",Command.OK,1); private Command cancelCommand = new

Command("Cancel",Command.CANCEL,1); private NamaTanaman namaTanaman; private Display display;

Tanaman tanaman;

public DeskripsiTanaman(Display d, NamaTanaman namaTanaman,String nama){

super("Deskripsi Tanaman","",65536,TextField.ANY); this.nama=nama;

this.display=d;

this.namaTanaman=namaTanaman;

tanaman = new Tanaman(); init_app();

}

public DeskripsiTanaman(Display d, NamaTanaman namaTanaman,String nama,Tanaman tanaman){ super("Deskripsi Tanaman",tanaman.getInfo(),65536,TextField.ANY); this.nama=nama; this.display=d; this.namaTanaman=namaTanaman; this.tanaman=tanaman; init_app(); }

private void init_app(){ addCommand(saveCommand); addCommand(cancelCommand); setCommandListener(this); }

public void commandAction(Command c,Displayable d){ if(c==saveCommand){

tanaman.setNama(nama);

tanaman.setInfo(getString()); Alert saveInfo = new Alert("Save Tanaman","",null,AlertType.INFO);

if(namaTanaman.togaDB.save(tanaman)){ saveInfo.setString("Success !"); // namaTanaman.home.deleteAll();

// Vector gunas = namaTanaman.togaDB.retrieveAll(); // for (int i = 0; i < gunas.size(); i++) {

// Tanaman app = (Tanaman) gunas.elementAt(i); // namaTanaman.home.append(app.getNama(), null); // } }else{ saveInfo.setString("Fail !"); } System.out.println(namaTanaman.home.getString(0)); display.setCurrent(saveInfo,namaTanaman.home); }else if(c==cancelCommand){ display.setCurrent(namaTanaman); } } } NamaKegunaan.java : /*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.List; import javax.microedition.lcdui.TextBox; import javax.microedition.lcdui.TextField; /** * * @author Ulum */

public class NamaKegunaan extends TextBox implements CommandListener{ private Guna guna;

public String nama=""; public List home;

private Display display;

private Command nextCommand = new Command("Next",Command.OK,1); private Command cancelCommand = new

Command("Cancel",Command.CANCEL,1); private CaraKegunaan caraKegunaan; public GunaDB gunaDB;

public NamaKegunaan(Display display,List home,GunaDB gunaDB,int idTanaman){

super("Nama Kegunaan","",64,TextField.ANY); this.gunaDB=gunaDB;

this.display=display; this.home=home;

guna = new Guna();

guna.setTanamanId(idTanaman); init_app();

public NamaKegunaan(Display display,List home,GunaDB gunaDB,Guna guna){ super("Nama Tanaman",guna.getNama(),65536,TextField.ANY); this.gunaDB=gunaDB; this.home=home; this.display=display; this.guna=guna; init_app(); }

private void init_app(){ addCommand(nextCommand); addCommand(cancelCommand); setCommandListener(this); }

public void commandAction(Command c,Displayable d){ if(c==nextCommand){

this.nama=getString();

caraKegunaan = new CaraKegunaan(display, this, nama,guna); display.setCurrent(caraKegunaan); }else if(c==cancelCommand){ display.setCurrent(home); } } } CaraKegunaan.java : /*

* To change this template, choose Tools | Templates * and open the template in the editor.

*/ package com.ta.toga; import java.util.Vector; 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.TextBox; import javax.microedition.lcdui.TextField; /** * * @author Ulum */

public class CaraKegunaan extends TextBox implements CommandListener {

private Command saveCommand = new Command("Save",Command.OK,1); private Command cancelCommand = new

Command("Cancel",Command.CANCEL,1); private NamaKegunaan namaKegunaan; private Display display;

private Guna guna; private String nama;

public CaraKegunaan(Display d, NamaKegunaan namaKegunaan,String nama,Guna guna){

super("Cara pengobatan",guna.getCara(),65536,TextField.ANY); this.namaKegunaan=namaKegunaan; this.display=d; this.guna=guna; this.nama=nama; init_app(); }

private void init_app(){ addCommand(saveCommand); addCommand(cancelCommand); setCommandListener(this); }

public void commandAction(Command c,Displayable d){ if(c==saveCommand){

guna.setNama(nama);

guna.setCara(getString());

Alert saveInfo = new Alert("Save Kegunaan Tanaman","",null,AlertType.INFO); saveInfo.setTimeout(Alert.FOREVER); if(namaKegunaan.gunaDB.save(guna)){ saveInfo.setString("Success !"); namaKegunaan.home.deleteAll(); Vector gunas = namaKegunaan.gunaDB.retrieveByTanaman(guna.getTanamanId()); for (int i = 0; i < gunas.size(); i++) { Guna app = (Guna) gunas.elementAt(i);

namaKegunaan.home.append(app.getNama(), null); } }else{ saveInfo.setString("Fail !"); } display.setCurrent(saveInfo,namaKegunaan.home); }else if(c==cancelCommand){ display.setCurrent(namaKegunaan); } }

Dokumen terkait