Thursday, March 15, 2012

Pemrograman Visual - Laporan 1

Kali ini Tugasku akan membahas tentang cara menampilkan antarmuka yang ada di J2ME antara lain Display, Diplayable, Ticker, Item, Form, TextField, StringItem, ImageItem, DateField, ChioceGroup, Gauge, List, TextBpx dan Alert. Dimana nantinya kita akan membahasnya secara detail.
Berikut langkah-langkah membuat projeknya :
  •     Pilih New Project – Mobile – Mobile Application.
  •     Hapus centang pada set as main project dengan create xxx.
  •     Klik  next dan centang pada CLDC-1.1 dan MIDP-2.1 ( tipe CLDC dan MIDP bisa diganti tergantung kebutuhan HPnya.
  •     Finish.
  •     Klik kanan pada default package – Midlet.
  •    Kemudian beri nama laporan2 ( nama bisa diganti terserah kita )
  •    Kemudian kita memulai memrogram
Berikut menu-menu yang ada :
Menu

 
 Choice Group

Image

Date Field

 Gauge

 List

 TextField

 TextBox


 Alert


Kemudian kita lanjutkan ke penjelasan source code secara lengkap, sementara kita buat class midletnya kemudian beri nama yang sama seperti kita inginkan. Setelah itu kita buat construktornya.
 
public laporan2() {
    }

Selanjutnya kita definisikan apa aja yang dibutuhkan dan kita buat private supaya tidak bisa diakses lain.

private Display display;
     private Form frm1,fmTextF,fmImage,fmChoiceGroup,fmDate,fmGauge,fmAlert;
     private Command image,TF, Exit, Back, group, date, gauge, list, TB, alert;
     private TextField textfield,textfield1,textfield2,textfield3,textfield4,textfield5,textfield6;
     private ChoiceGroup cgProdi, choicePopup,choiceMulti;
     private DateField dateonly, timeonly, datetime;
     private Gauge iGauge,nonIGauge;
     private int choiceGroupIndex,popGroupIndex,multiGroupIndex;
     private List listHardware;
     private TextBox texbok;
     private StringItem siLabel;
     private Alert alarm, confirm,info, warning, error;
     private boolean midletPaused = false;
     Ticker tfTicker;
     Image img;


Setelah didefinisikan kita buat tombol apa saja yang kita butuhkan seperti berikut.

//membuat tombol
                alert = new Command("Alert", Command.SCREEN, 0);
                TB = new Command("Text Box", Command.SCREEN, 0);
                list = new Command("List", Command.SCREEN, 0);
                gauge = new Command("Gauge", Command.SCREEN, 0);
                date = new Command("Date Field", Command.SCREEN, 0);
                group = new Command("Choice Group", Command.SCREEN, 0);
                image = new Command("Image", Command.SCREEN, 0);
                TF = new Command("Text Field", Command.SCREEN, 0);
                Exit = new Command("Exit", Command.EXIT, 0);
                Back = new Command("Back", Command.BACK, 0);
//=================================================================================

Tombol sudah jadi sekarabg kita membuat untuk tampilan Form pertanma yaitu mulai item yang ditampilkan sampai formnya.
Form Pertama.
//membuat form utama
                frm1 = new Form("My Aplication");
                siLabel = new StringItem("Selamat datang diaplikasi saya ", null);
                tfTicker = new Ticker("Welcome To My Application");
                frm1.setTicker(tfTicker);
                frm1.append(siLabel);
                frm1.addCommand(Exit);
                frm1.addCommand(group);
                frm1.addCommand(image);
                frm1.addCommand(date);
                frm1.addCommand(gauge);
                frm1.addCommand(list);
                frm1.addCommand(TF);
                frm1.addCommand(TB);
                frm1.addCommand(alert);
                frm1.setCommandListener(this);



Form kedua menampilkan TextField 
//=================================================================================
                //membuat form TextFielld
                fmTextF = new Form("Macam-macam Text Field");
                textfield = new TextField("Masukkan apapun : ", "", 30, TextField.ANY);
                textfield1 = new TextField("Email : ", "", 30, TextField.EMAILADDR);
                textfield2 = new TextField("Numeric : ", "", 30, TextField.NUMERIC);
                textfield3 = new TextField("URL : ", "", 30, TextField.URL);
                textfield4 = new TextField("Decimal : ", "", 30, TextField.DECIMAL);
                textfield5 = new TextField("Phonenumber : ", "", 30, TextField.PHONENUMBER);
                textfield6 = new TextField("Password : ", "", 30, TextField.PASSWORD);
                fmTextF.addCommand(Back);
                fmTextF.setCommandListener(this);
//=================================================================================

Form ketiga untuk menampilkan sebuah gambar.
//=================================================================================
                //membuat form image
                fmImage = new Form("Image");
                try {
                img=Image.createImage("/laporan2/laporan2.jpg");
                } catch (Exception e){
                }
                fmImage.addCommand(Back);
                fmImage.setCommandListener(this);
//=================================================================================
Sebelumnya kita harus kopikan gambar dalam package class kita.

Form keempat untuk menampilkan ChoiceGroup
 
//=================================================================================
                 //membuat form choice group
                fmChoiceGroup = new Form("Choice Group");
                cgProdi = new ChoiceGroup("Kelamin", Choice.EXCLUSIVE);
                cgProdi.append("Laki-laki", null);
                cgProdi.append("Perempuan", null);

                choicePopup = new ChoiceGroup("Prodi", Choice.POPUP);
                choicePopup.append("Manajemen Informatika", null);
                choicePopup.append("Teknik Komputer", null);

                choiceMulti = new ChoiceGroup("UKM", Choice.MULTIPLE);
                choiceMulti.append("UKMJ TI", null);
                choiceMulti.append("LUMUT", null);
                choiceMulti.append("Olahraga", null);
                fmChoiceGroup.addCommand(Back);
                fmChoiceGroup.setCommandListener(this);
//=================================================================================

Form kelima untuk menampilkan DateField.
//=================================================================================
                //membuat form Date Field
                fmDate = new Form("Date Field");
                dateonly = new DateField("Birthday (DATE)", DateField.DATE);
                timeonly = new DateField("Set Alarm (TIME)", DateField.TIME);
                datetime = new DateField("Departure (DATE TIME)", DateField.DATE_TIME);
                fmDate.addCommand(Back);
                fmDate.setCommandListener(this);
//=================================================================================

Form keenam untuk menampilkan Gauge.
//=================================================================================
                //membuat form Gauge
                fmGauge = new Form("Gauge");
                iGauge = new Gauge("Volume", true, 10, 0);
                nonIGauge = new Gauge("Loading", false,Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);
                fmGauge.addCommand(Back);
                fmGauge.setCommandListener(this);
//=================================================================================

Menampilkan sebuah List.
//=================================================================================
                //membuat List
                listHardware = new List("Hardware",List.IMPLICIT);
                listHardware.append("Harddisk", null);
                listHardware.append("Floppydisk", null);
                listHardware.append("RAM", null);
                listHardware.append("Power Supply", null);
                listHardware.append("Sounds", null);
                listHardware.append("Fan", null);
                listHardware.addCommand(Back);
                listHardware.setCommandListener(this);
//=================================================================================

Menampilkan sebuah TextBox
//=================================================================================
                //membuat Text Box
                texbok = new TextBox("Message","",255,TextField.ANY);
                texbok.addCommand(Back);
                texbok.setCommandListener(this);
//=================================================================================

Menampilkan sebuah Alert
//=================================================================================
                //membuat Alert
                fmAlert = new Form ("Macam Alert");
                alarm = new Alert("Alarm Alert", "Example of an Alarm type of Alert",null, AlertType.ALARM);
                alarm.addCommand(Back);
                alarm.setCommandListener(this);

Kemudian kita beralih ke commandAction(Command c, Displayable d)

Tombol TextField
if(c == TF){
                    fmTextF.append(textfield);
                    fmTextF.append(textfield1);
                    fmTextF.append(textfield2);
                    fmTextF.append(textfield3);
                    fmTextF.append(textfield4);
                    fmTextF.append(textfield5);
                    fmTextF.append(textfield6);
                    display.setCurrent(fmTextF);

                } 

Tombol Choice Group.
else if(c == group){
                    choiceGroupIndex = fmChoiceGroup.append(cgProdi);
                    popGroupIndex = fmChoiceGroup.append(choicePopup);
                    multiGroupIndex = fmChoiceGroup.append(choiceMulti);
                    display.setCurrent(fmChoiceGroup);

                 } 

Tombol Image.
else if(c == image){
                    fmImage.append(img);
                    display.setCurrent(fmImage);

                 } 

Tombol Date Field.
else if(c == date){
                    fmDate.append(dateonly);
                    fmDate.append(timeonly);
                    fmDate.append(datetime);
                    display.setCurrent(fmDate);

                  }

Tombol Gauge.
else if(c == gauge){
                    fmGauge.append(iGauge);
                    fmGauge.append(nonIGauge);
                    display.setCurrent(fmGauge);
                    
                  } 

Tombol List
else if(c == list){
                    display.setCurrent(listHardware);

                  } 

Tombol Text Box
else if(c == TB){
                    display.setCurrent(texbok);

                  } 

Tombol Alert
else if(c == alert){
                    display.setCurrent(alarm);

                  }

Tombol Exit
else if(c == Exit){
                    destroyApp(true);
                    notifyDestroyed();

                  } 

Tombol Back
else if(c == Back){
                    display.setCurrent(frm1);
                  }

Semua class telah dijelaskan per itemnya, jika ingin Souce Code-nya lengkap download DISINI.

SEMOGA BERMANFAAT  \(^o^)/

7 comments:

 
Design by Ariema Babycorn