Praktikum ke - 1
J2ME (Java 2 Micro Edition) merupakan subset dari J2SE yang ditujukan untuk implementasi pada peralatan embeded system dan handheld yang tidak mampu mendukung secara penuh implementasi menggunakan J2SE.
J2ME adalah teknologi Java yang diperuntukkan perngkat-perngakat kecilconsumer device , terutama wireless. Bebrapa perangkat wireless antara lain PC, PDA, communicator, embedded device, smart card dan ponsel. Teknologi Java mungkin merupakan satu-satunya cara memprogram beberapa perangkat, berbagi logic antara perangkat dan server, pengantaran aplikasi secara dinamis, program yang kompak, lingkungan pengembangan yang aman dan cepat. J2ME memungkinkan perangkat lunak dapat di-download perangkat sekaligus memungkinkan layanan yang dapat disesuaikan di beragam perangkat.
J2ME Profile
J2ME Profile mengimplementasikan kemampuan / fitur lain yang sangat bergantung pada jenishandheld yang digunakan.
Ada lima kategori J2ME Profile saat ini, yakni :
a. Mobile Information Devise Profile
MIDP menyediakan librari-librari java untuk implementasi dasar antarmuka (GUI), imp-lementasi jaringan (networking), database dan timer. MIDP dirancang khususnya untuk wireless phone danpager.
b. Foundation Profile
Profile dasar untuk non-GUI network device pada CDC
c. Personal Profil, RMI Profile, Personal Digital Assistant Profile
Standar grafik, Generasi selanjutnya dari lingkungan personal java, dan RMI yang support untuk CDC dan profile standart device.
MIDlet
MIDlet merupakan aplikasi yang dijalankan pada sebuah perangkat handheld. MIDlet tidak berinteraksi langsung dengan hardware dari handheld devices, melainkan berinteraksi melalui AMS (Application Management Software). AMS inilah yang akan menerima sinyal dari MIDlet bahwa MIDlet akan dijalakan atau berhenti.
MIDP mendefinisikan kelas-kelas library berikut untuk membangun aplikasi:
a. Javax.microediton.midlet, merupkan package yang berisi kelas-kelas untuk mengatur daur hidup midlet.
b. Javax.microedition.lcdui, merupakan package yang berisi kelas-kelas yang user interface dan pemrograman GUI.
c. Javax.microedition.io, merupakan.package yang berisi kelas-kelas dan antarmuka untuk midp pemrograman jaringan.
d. Javax.io, java.lang and java.util, merupakan package yang berisi I/O, language dan kelas-kelasutility.
Berikut adalah tampilan awal pemrograman mobile pembuatan profil data diri :
Tampilan pada saat pengisian data adalah seperti berikut :
Tampilan TextBox :
Tampilan List :
Source Code bisa di download Klik Disini
Source Code bisa di baca di bawah ini :package pkgprofil;
import java.util.Date;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* @author Ayudya Tria Afriana
*/
public class profilMidlet extends MIDlet implements CommandListener {
private Display display;
private Form fmCurriculumVitae, fmResume;
private Command cmOk,cmExit,cmBack,cmTB, cmList;
private TextField tfNama,tfNIM,tfAlamat,tfTmptLahir,tfTglLahir;
private ChoiceGroup cgProdi;
private int choiceGroupIndex;
private StringItem siNama, siNIM, siAlamat,
siTmptLhr, siTglLhr,siProdi;
private DateField dtField;
private Image img, img2;
private Gauge ge;
private TextBox TB;
private List list;
private boolean midletPaused = false;
public void startApp() {
display = Display.getDisplay(this);
try {
img = Image.createImage("/pkgprofil/a.jpg");
}
catch(Exception e) {}
try {
img2 = Image.createImage("/pkgprofil/b.jpg");
}
catch(Exception e) {}
//membuat tombol
cmExit = new Command("Exit", Command.EXIT, 0);
cmOk = new Command("Ok", Command.SCREEN, 0);
cmBack = new Command("Back", Command.BACK, 0);
cmTB = new Command("TextBox", Command.SCREEN, 0);
cmList = new Command("List", Command.SCREEN,0);
dtField = new DateField("Date", DateField.DATE_TIME);
dtField.setDate(new Date());
ge = new Gauge("Loading", false,
Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);
//textfield untuk data pribadi
tfNama = new TextField ("Name : ", "", 30, TextField.ANY);
tfNIM = new TextField ("NRP : ", "", 30, TextField.ANY);
tfAlamat = new TextField ("Address : ", "", 30, TextField.ANY);
tfTmptLahir = new TextField ("City : ", "", 30, TextField.ANY);
tfTglLahir = new TextField ("D/M/Y : ", "", 30, TextField.ANY);
TB = new TextBox("Message","",255,TextField.ANY);
TB.addCommand(cmBack);
TB.setCommandListener(this);
//pemilihan Prodi
cgProdi = new ChoiceGroup("Prodi", Choice.EXCLUSIVE);
//meng-append pilihan atau choice
cgProdi.append("Computer Engineering", null);
cgProdi.append("Informatic Management", null);
cgProdi.append("Clinical Nutrition", null);
cgProdi.append("Medical Record", null);
//membuat form dan memasukkan komponen
fmCurriculumVitae = new Form("Curriculum Vitae");
fmCurriculumVitae.addCommand(cmExit);
fmCurriculumVitae.addCommand(cmTB);
fmCurriculumVitae.addCommand(cmOk);
fmCurriculumVitae.addCommand(cmList);
fmCurriculumVitae.append(dtField);
fmCurriculumVitae.append(img);
fmCurriculumVitae.append(tfNama);
fmCurriculumVitae.append(tfNIM);
fmCurriculumVitae.append(tfAlamat);
fmCurriculumVitae.append(tfTmptLahir);
fmCurriculumVitae.append(tfTglLahir);
choiceGroupIndex = fmCurriculumVitae.append(cgProdi);
fmCurriculumVitae.append(ge);
fmCurriculumVitae.setCommandListener(this);
//membuat form hasil input user
fmResume = new Form("Your Profile");
//membuat string item untuk menampilkan text dan pilihan yang diisi
siNama = new StringItem("Name : ", null);
siNIM = new StringItem("NRP : ", null);
siAlamat = new StringItem("Address : ", null);
siTmptLhr = new StringItem("City : ", null);
siTglLhr = new StringItem("D/M/Y : ", null);
siProdi = new StringItem("Study : ", null);
//menampilkan StringItem yang nanti akan diisi oleh data hasil input user
fmResume.append(img);
fmResume.append(siNama);
fmResume.append(siNIM);
fmResume.append(siAlamat);
fmResume.append(siTmptLhr);
fmResume.append(siTglLhr);
fmResume.append(siProdi);
//menambahkan command
fmResume.addCommand(cmBack);
fmResume.setCommandListener(this);
//Menambahkan TB
TB = new TextBox("Output TextBox", null,255, TextField.ANY);
TB.addCommand(cmBack);
TB.setCommandListener(this);
//Menambahkan list
list = new List("My List Hobby", Choice.IMPLICIT);
list.append("Memasak", img2);
list.append("Editing Foto", img2);
list.append("Ngemil", img2);
list.append("Baca Novel", img2);
list.addCommand(cmBack);
list.setCommandListener(this);
//menampilkan form DataPribadi sebagai tampilan awal
display.setCurrent(fmCurriculumVitae);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (d == fmCurriculumVitae){
String nama,nim,alamat,tmptlhr,tgllhr,prodi = null;
//jika tombol/command OK ditekan
if(c == cmOk){
//mendapatkan inputan user
nama = tfNama.getString();
nim = tfNIM.getString();
alamat = tfAlamat.getString();
tmptlhr = tfTmptLahir.getString();
tgllhr = tfTglLahir.getString();
prodi = cgProdi.getString(cgProdi.getSelectedIndex());
//memasukkan hasil input ke StringItem
siNama.setText(nama);
siNIM.setText(nim);
siAlamat.setText(alamat);
siTmptLhr.setText(tmptlhr);
siTglLhr.setText(tgllhr);
siProdi.setText(prodi);
//menampilkan form hasil setelah cmOk ditekan
display.setCurrent(fmResume);
}else if(c == cmExit){ //jika tombol/command Exit ditekan
destroyApp(true);
notifyDestroyed();
}else if(c == cmTB){
TB.setString(tfNama.getString()+"\n"+tfNIM.getString()+""
+"\n"+tfAlamat.getString()+"\n"+tfTmptLahir.getString()+""
+"\n"+tfTglLahir.getString());
display.setCurrent(TB);
}else if (c == cmList){
display.setCurrent(list);
}
}if (d == fmResume){
if(c == cmBack){
//jika tombol/command Back ditekan
//menampilkan kembali form DataPribadi sebagai tampilan default/awal
display.setCurrent(fmCurriculumVitae);
}
}if (d == TB){
if (c == cmBack){
display.setCurrent(fmCurriculumVitae);
}
}if (d == list){
if (c == cmBack){
display.setCurrent(fmCurriculumVitae);
}
}
}
}
import java.util.Date;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* @author Ayudya Tria Afriana
*/
public class profilMidlet extends MIDlet implements CommandListener {
private Display display;
private Form fmCurriculumVitae, fmResume;
private Command cmOk,cmExit,cmBack,cmTB, cmList;
private TextField tfNama,tfNIM,tfAlamat,tfTmptLahir,tfTglLahir;
private ChoiceGroup cgProdi;
private int choiceGroupIndex;
private StringItem siNama, siNIM, siAlamat,
siTmptLhr, siTglLhr,siProdi;
private DateField dtField;
private Image img, img2;
private Gauge ge;
private TextBox TB;
private List list;
private boolean midletPaused = false;
public void startApp() {
display = Display.getDisplay(this);
try {
img = Image.createImage("/pkgprofil/a.jpg");
}
catch(Exception e) {}
try {
img2 = Image.createImage("/pkgprofil/b.jpg");
}
catch(Exception e) {}
//membuat tombol
cmExit = new Command("Exit", Command.EXIT, 0);
cmOk = new Command("Ok", Command.SCREEN, 0);
cmBack = new Command("Back", Command.BACK, 0);
cmTB = new Command("TextBox", Command.SCREEN, 0);
cmList = new Command("List", Command.SCREEN,0);
dtField = new DateField("Date", DateField.DATE_TIME);
dtField.setDate(new Date());
ge = new Gauge("Loading", false,
Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);
//textfield untuk data pribadi
tfNama = new TextField ("Name : ", "", 30, TextField.ANY);
tfNIM = new TextField ("NRP : ", "", 30, TextField.ANY);
tfAlamat = new TextField ("Address : ", "", 30, TextField.ANY);
tfTmptLahir = new TextField ("City : ", "", 30, TextField.ANY);
tfTglLahir = new TextField ("D/M/Y : ", "", 30, TextField.ANY);
TB = new TextBox("Message","",255,TextField.ANY);
TB.addCommand(cmBack);
TB.setCommandListener(this);
//pemilihan Prodi
cgProdi = new ChoiceGroup("Prodi", Choice.EXCLUSIVE);
//meng-append pilihan atau choice
cgProdi.append("Computer Engineering", null);
cgProdi.append("Informatic Management", null);
cgProdi.append("Clinical Nutrition", null);
cgProdi.append("Medical Record", null);
//membuat form dan memasukkan komponen
fmCurriculumVitae = new Form("Curriculum Vitae");
fmCurriculumVitae.addCommand(cmExit);
fmCurriculumVitae.addCommand(cmTB);
fmCurriculumVitae.addCommand(cmOk);
fmCurriculumVitae.addCommand(cmList);
fmCurriculumVitae.append(dtField);
fmCurriculumVitae.append(img);
fmCurriculumVitae.append(tfNama);
fmCurriculumVitae.append(tfNIM);
fmCurriculumVitae.append(tfAlamat);
fmCurriculumVitae.append(tfTmptLahir);
fmCurriculumVitae.append(tfTglLahir);
choiceGroupIndex = fmCurriculumVitae.append(cgProdi);
fmCurriculumVitae.append(ge);
fmCurriculumVitae.setCommandListener(this);
//membuat form hasil input user
fmResume = new Form("Your Profile");
//membuat string item untuk menampilkan text dan pilihan yang diisi
siNama = new StringItem("Name : ", null);
siNIM = new StringItem("NRP : ", null);
siAlamat = new StringItem("Address : ", null);
siTmptLhr = new StringItem("City : ", null);
siTglLhr = new StringItem("D/M/Y : ", null);
siProdi = new StringItem("Study : ", null);
//menampilkan StringItem yang nanti akan diisi oleh data hasil input user
fmResume.append(img);
fmResume.append(siNama);
fmResume.append(siNIM);
fmResume.append(siAlamat);
fmResume.append(siTmptLhr);
fmResume.append(siTglLhr);
fmResume.append(siProdi);
//menambahkan command
fmResume.addCommand(cmBack);
fmResume.setCommandListener(this);
//Menambahkan TB
TB = new TextBox("Output TextBox", null,255, TextField.ANY);
TB.addCommand(cmBack);
TB.setCommandListener(this);
//Menambahkan list
list = new List("My List Hobby", Choice.IMPLICIT);
list.append("Memasak", img2);
list.append("Editing Foto", img2);
list.append("Ngemil", img2);
list.append("Baca Novel", img2);
list.addCommand(cmBack);
list.setCommandListener(this);
//menampilkan form DataPribadi sebagai tampilan awal
display.setCurrent(fmCurriculumVitae);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (d == fmCurriculumVitae){
String nama,nim,alamat,tmptlhr,tgllhr,prodi = null;
//jika tombol/command OK ditekan
if(c == cmOk){
//mendapatkan inputan user
nama = tfNama.getString();
nim = tfNIM.getString();
alamat = tfAlamat.getString();
tmptlhr = tfTmptLahir.getString();
tgllhr = tfTglLahir.getString();
prodi = cgProdi.getString(cgProdi.getSelectedIndex());
//memasukkan hasil input ke StringItem
siNama.setText(nama);
siNIM.setText(nim);
siAlamat.setText(alamat);
siTmptLhr.setText(tmptlhr);
siTglLhr.setText(tgllhr);
siProdi.setText(prodi);
//menampilkan form hasil setelah cmOk ditekan
display.setCurrent(fmResume);
}else if(c == cmExit){ //jika tombol/command Exit ditekan
destroyApp(true);
notifyDestroyed();
}else if(c == cmTB){
TB.setString(tfNama.getString()+"\n"+tfNIM.getString()+""
+"\n"+tfAlamat.getString()+"\n"+tfTmptLahir.getString()+""
+"\n"+tfTglLahir.getString());
display.setCurrent(TB);
}else if (c == cmList){
display.setCurrent(list);
}
}if (d == fmResume){
if(c == cmBack){
//jika tombol/command Back ditekan
//menampilkan kembali form DataPribadi sebagai tampilan default/awal
display.setCurrent(fmCurriculumVitae);
}
}if (d == TB){
if (c == cmBack){
display.setCurrent(fmCurriculumVitae);
}
}if (d == list){
if (c == cmBack){
display.setCurrent(fmCurriculumVitae);
}
}
}
}
Tidak ada komentar:
Posting Komentar