JAVA

SIMPLE APPLICATION J2ME LIST

Hari ini lagi belajar j2me, terus ada sedikit tugas dari dosennya buat sebuah aplikasi dari list. Kurang lebih sieh tugasnya itu kayak gini, pas pertama muncul list type nya itu implicit n ada 3 menu, yaitu exit, next ama select.Nah ketika kita klik next maka akan pindah ke list dengan type exclusive dan klo next di klik lagi di type ini maka akan ke type list multiple.Dan klo select maka kita dapat memunculkan apa yang udah kita pilih di tipe list. Daripada bingung kayak gini nieh source nya. Moga Bermanfaat.

package com;

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

public class Tugas3 extends MIDlet implements CommandListener {
    private Display display;
    private List implicit,exclusive,multiple;
    private Command menu,exit,next,select;
    Image image[] = null;
    String pilih[] = {"First","Second","Third","Fourth"};

    public Tugas3(){
        implicit = new List("Implicit", Choice.IMPLICIT, pilih, image);
        exclusive = new List("Implicit", Choice.EXCLUSIVE, pilih, image);
        multiple = new List("Implicit", Choice.MULTIPLE, pilih, image);

        exit = new Command("Exit",Command.OK,2);
        next = new Command("Next",Command.OK,3);
        select = new Command("Select",Command.OK,3);

        implicit.addCommand(exit);
        implicit.addCommand(next);
        implicit.addCommand(select);
        implicit.setCommandListener(this);

        exclusive.addCommand(exit);
        exclusive.addCommand(next);
        exclusive.addCommand(select);
        exclusive.setCommandListener(this);

        multiple.addCommand(exit);
        multiple.addCommand(next);
        multiple.addCommand(select);
        multiple.setCommandListener(this);

    }

    public void select(List listCk){
        Alert alert;
        if(listCk == implicit){
            int idx = implicit.getSelectedIndex();
            String st = "Your selectrion is"+implicit.getString(idx);
            alert = new Alert("Implicit Selection");
            alert.setString(st);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert,implicit);
        }
        else if(listCk ==exclusive){
            if(exclusive.isSelected(0)){
                int idx = exclusive.getSelectedIndex();
            String st = "Your selectrion is"+exclusive.getString(idx);
            alert = new Alert("Explicit Selection");
            alert.setString(st);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert,implicit);

            }
        }
        else if(listCk ==multiple){
            if(exclusive.isSelected(0)){
                StringBuffer b = new StringBuffer();
                for (int i = 0; i < multiple.size(); i++) {
                if (multiple.isSelected(i)) {
                    b.append("Your selection" + multiple.getString(i));
                    b.append("\n");
                }
            }
                alert = new Alert("Multiple :") ;
                alert.setString(b.toString()) ;
                alert.setTimeout(Alert.FOREVER) ;
                display.setCurrent(alert, multiple);

            }
        }
    }
    public void startApp() {
        display = Display.getDisplay(this);
        display.setCurrent(implicit);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }

    public void commandAction(Command c, Displayable d) {
           if(c == next){
                if(implicit.isShown()){
                    display.setCurrent(exclusive);
                }
                else if(exclusive.isShown()){
                    display.setCurrent(multiple);
                }
           }
           if(c == exit){
                if(exclusive.isShown()){
                    display.setCurrent(implicit);
                }
                else if(multiple.isShown()){
                    display.setCurrent(exclusive);
                }
                else if(implicit.isShown()){
                    destroyApp(true);
                }
           }
           if(c == select){
                if(exclusive.isShown()){
                    select(exclusive);
                }
                else if(multiple.isShown()){
                    select(multiple);
                }
                else if(implicit.isShown()){
                    select(implicit);
                }
           }
    }
}
Standar

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s