Selasa, 28 Februari 2012

How to Create Mobile MidLet

Image 1

Image2
Image3

Image4



import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;


public class Praktekif2 extends MIDlet implements
        CommandListener {
        Display d;
        Form f;
        Image img;
        Command cmdKeluar,cmdBeli,cmdProses,cmdKembali;
        //deklarasi variabel form 2
        Form f2;
        TextField txtKode,txtNama,txtHarga;
        ChoiceGroup cgSatuan;
        ///deklarsi variabel form 3
        private Form f3;
        private StringItem siKode,siNama,siSatuan,siHarga,siKet;
        private Command cmdKembali2;
        //akhir deklarasi
        public Praktekif2(){
        d=Display.getDisplay(this);
        f=new Form("Halaman Utama");
        try {
        img=Image.createImage("/edit.jpg");
        }catch(Exception e) {
            e.printStackTrace();
            System.out.println("Gambar Tidak Ada");
        }
        cmdKeluar=new Command("Keluar",Command.EXIT,0);
        cmdBeli=new Command("Beli",Command.OK,1);
        f.setTicker(new Ticker("Ivo Randi.MS"));
        f.append(img);
        f.addCommand(cmdBeli);
        f.addCommand(cmdKeluar);
        f.setCommandListener(this);
        }

   
       
      
    public void startApp() {
        d.setCurrent(f);
    }
   

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c,Displayable s){
        if(c==cmdKeluar){
            destroyApp(true);
            notifyDestroyed();
        }else if (c==cmdBeli){
            f2=new Form("Entry Barang");
            f2.setTicker(new Ticker("Pilih Barang"));
            cmdKembali=new Command("Kembali",Command.BACK,0);
            cmdProses=new Command("Proses",Command.OK,1);
            txtKode=new TextField("Kode Barang","",20,TextField.ANY);
            txtNama=new TextField("Nama Barang","",20,TextField.ANY);
            txtHarga=new TextField("Harga Barang","",10,TextField.NUMERIC);
            cgSatuan=new ChoiceGroup("Satuan",Choice.EXCLUSIVE);
            cgSatuan.append("KG", img);
            cgSatuan.append("BOX", img);
            f2.addCommand(cmdKembali);
            f2.addCommand(cmdProses);
            f2.setCommandListener(this);
            f2.append(txtKode);
            f2.append(txtNama);
            f2.append(txtHarga);
            f2.append(cgSatuan);
            d.setCurrent(f2);
       
        }else if(s==f2){
            if(c==cmdKembali){
                d.setCurrent(f);
            }else if(c==cmdProses){
                int Harga=0;
                String Keterangan="";
                //mengkonversi nilai
                Harga=Integer.parseInt(txtHarga.getString());
                if(Harga>=50000){
                    Keterangan="Anda Dapat Diskon 20%";
                }else{
                    Keterangan="Tidak Ada Diskon,Maaf ya...";
                }
                f3=new Form ("DATA BARANG");
                siKode=new StringItem("Kode Barang :",txtKode.getString());
                siKode.setFont (Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD|Font.STYLE_UNDERLINED,Font.SIZE_MEDIUM));
                siNama=new StringItem("Nama Barang ;",txtNama.getString());    
                siNama.setFont (Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
                siSatuan=new StringItem("Satuan ;",cgSatuan.getString(0));    
                siSatuan.setFont (Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
                siHarga=new StringItem("Harga Barang ;",txtHarga.getString());    
                siHarga.setFont (Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
               
                siKet=new StringItem("Keterangan :",Keterangan);
                siKet.setFont (Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
                cmdKembali2=new Command("Kembali",Command.BACK,0);
                //menambahkan objek kedalam form 3
                f3.addCommand(cmdKembali2);
               
                f3.append(siKode);
                f3.append(siNama);
                f3.append(siSatuan);
                f3.append(siHarga);
                f3.append(siKet);
                f3.setCommandListener(this);
               
                d.setCurrent(f3);
            }
           
         
        }
    }
}

Tidak ada komentar :

Posting Komentar