Posts Tagged ‘ItemCommandListener

11
Dec
08

membuat Button dari StringItem di J2ME

hmmm ada pertanyaan lagi pas mo ngerjain TA
gmn ya bikin button pada form di Midlet

cari2 di example ternyata ketemu,lagi2 sederhana heheh ga sesusah yang dibayangkan karena API Midp 2.0 udah lumayan lenkap
sama kek ItemStateListener yg pernh aq tulis dulu
lagi2 di J2ME kebanyakan pake Interface
nah tryt ada interface untuk item command listener ItemCommandListener

nah drpd disimpen ndiri skr aq tulis deh disini
biasa langkah2 dulu hehehe
1. implemen dulu interface ItemCommandListener ke midlet

  • public class StringButton extends MIDlet implements ItemCommandListener {
    }
  • 2. pilih tipe StringItem menjadi BUTTON dan set default commandnya

  • item = new StringItem(“Button “, “Button”, Item.BUTTON);
    item.setDefaultCommand(CMD_OK);
    item.setItemCommandListener(this);
  • 3, dafultmethodnya harus ada

  • public void commandAction(Command c, Item item) {
    (c == CMD_OK) {
    String text = “tombol ok ditekan”;
    Alert alert = new Alert(“Action”, text, null, AlertType.INFO);
    display.setCurrent(alert);
    }
    }
  • contoh simple skrip lengkapnya dibawah ini


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

    public class StringButton extends MIDlet implements ItemCommandListener {
    private static final Command CMD_OK = new Command("Go", Command.ITEM, 1);
    private Display display;
    private Form mainForm;

    protected void startApp() {
    display = Display.getDisplay(this);

    mainForm = new Form("Button Demo");

    item = new StringItem("Button ", "Button", Item.BUTTON);
    item.setDefaultCommand(CMD_OK);
    item.setItemCommandListener(this);
    display.setCurrent(mainForm);
    }

    public void commandAction(Command c, Item item) {
    if (c == CMD_OK) {
    String text = "tekan tombol nie";
    Alert a = new Alert("Action", text, null, AlertType.INFO);
    display.setCurrent(a);
    }
    }

    public void commandAction(Command c, Displayable d) {
    destroyApp(false);
    notifyDestroyed();
    }

    protected void destroyApp(boolean unconditional) {
    }

    protected void pauseApp() {
    }
    }

    oke guys slamat mencoba
    smoga anda smakin suka dengan J2ME hehehe

    tunggu tulisan2 J2ME berikutx ya ntr mo bahas J2ME POLISH
    apaan tu?tgg ye… 😀




    Blog Stats

    • 11,044 hits

    Top Clicks

    • None

    free ms prita

    May 2024
    M T W T F S S
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    Categories

    RSS Viva News Technology

    • An error has occurred; the feed is probably down. Try again later.
    Join My Community at MyBloglog!

    Online Status

    Dukung Gerakan Ini

    Go Green Indonesia


    Greenpeace

    Join One Campaign

    Pages