Created
March 21, 2012 08:18
-
-
Save resarahadian/2145569 to your computer and use it in GitHub Desktop.
Membuat Menu ChoiceGroup J2ME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*@ author Resa C.R | |
*/ | |
import javax.microedition.midlet.*; | |
import javax.microedition.lcdui.*; | |
public class Buku extends MIDlet implements CommandListener | |
{ | |
private Display tampil; | |
private Ticker runText,runTextTampil; | |
private Form form,formTampil; | |
private TextField txtNoKTP; | |
private TextField txtNama; | |
private ChoiceGroup choiceBuku; | |
private ChoiceGroup choiceJudul; | |
private Command comKeluar,comOk,comKembali; | |
public Buku() | |
{ | |
runText = new Ticker("<<<Selamat Datang di rental buku online>>>"); | |
txtNoKTP = new TextField("No.KTP","",15,TextField.NUMERIC); | |
txtNama = new TextField("Nama","",30,TextField.ANY); | |
//check Box (multi select) | |
choiceBuku = new ChoiceGroup("Kategori Buku",Choice.MULTIPLE); | |
choiceBuku.append("Religi",null); | |
choiceBuku.append("Komputer",null); | |
choiceBuku.append("Bisnis",null); | |
//radio button (pilih salah satu) | |
choiceJudul = new ChoiceGroup("Judul Buku",Choice.EXCLUSIVE); | |
choiceJudul.append("Doa Membawa Berkah <Religi>",null); | |
choiceJudul.append("Java Programming <Komputer>",null); | |
choiceJudul.append("30 Menit Meraih Sukses <Bisnis>",null); | |
choiceJudul.append("Daripada wira - wiri mending Wirausaha <Bisnis>",null); | |
choiceJudul.append("Database <Komputer>",null); | |
comKeluar = new Command("Keluar",Command.EXIT,2); | |
comOk = new Command("OK",Command.OK,2); | |
} | |
public void startApp() | |
{ | |
tampil = Display.getDisplay(this); | |
form = new Form("Aplikasi Peminjaman Buku via Mobile Phone"); | |
form.append(txtNoKTP); | |
form.append(txtNama); | |
form.append(choiceBuku); | |
form.append(choiceJudul); | |
form.addCommand(comKeluar); | |
form.addCommand(comOk); | |
form.setCommandListener(this); | |
form.setTicker(runText); | |
tampil.setCurrent(form); | |
} | |
public void pauseApp() | |
{ | |
} | |
public void destroyApp(boolean unconditional) | |
{ | |
notifyDestroyed(); | |
} | |
public void Keluar() | |
{ | |
destroyApp(true); | |
} | |
public void Tampilkan() | |
{ | |
StringItem sNoKTP = new StringItem("",txtNoKTP.getString()); | |
StringItem sNama = new StringItem("",txtNama.getString()); | |
String strBuku = ""; | |
if(choiceBuku.isSelected(0)) | |
{ | |
strBuku = choiceBuku.getString(0); | |
} | |
else if(choiceBuku.isSelected(1)) | |
{ | |
strBuku = strBuku + " , " + choiceBuku.getString(1); | |
} | |
else if(choiceBuku.isSelected(2)) | |
{ | |
strBuku = strBuku + " , " + choiceBuku.getString(2); | |
} | |
StringItem sBuku = new StringItem("","Kategori Buku : " + strBuku); | |
StringItem sJudulBuku = new StringItem("","Judul Buku : " + choiceJudul.getString(choiceJudul.getSelectedIndex())); | |
formTampil = new Form("Data Peminjaman Buku"); | |
runTextTampil = new Ticker("visit www.marisharingilmu.wordpress.com"); | |
comKembali = new Command("Kembali",Command.BACK,2); | |
comKeluar = new Command("Keluar",Command.EXIT,2); | |
formTampil.append(sNoKTP); | |
formTampil.append(sNama); | |
formTampil.append(sBuku); | |
formTampil.append(sJudulBuku); | |
formTampil.addCommand(comKembali); | |
formTampil.addCommand(comKeluar); | |
formTampil.setTicker(runTextTampil); | |
formTampil.setCommandListener(this); | |
tampil.setCurrent(formTampil); | |
} | |
public void commandAction(Command com,Displayable dsp) | |
{ | |
String label = com.getLabel(); | |
if(label.equals("OK")) | |
{ | |
Tampilkan(); | |
} | |
else if(label.equals("Kembali")) | |
{ | |
tampil.setCurrent(form); | |
} | |
else if(label.equals("Keluar")) | |
{ | |
destroyApp(true); | |
notifyDestroyed(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment