Tuesday, August 19, 2014

remember java me midlet list , display , alert

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package simnumberkeeper;

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

/**
 * @author boroo
 */
public class Midlet extends MIDlet implements CommandListener {

    Display display;
    List list;

    public Midlet() {
    }

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

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    private Screen getIndexDisplay() {
        list = new List("SIM Numbers", List.MULTIPLE);
        list.append("string part 1", null);
        list.append("string part 2", null);
        list.append("string part 3", null);
        list.addCommand(new Command("OKEY", Command.ITEM, 1));
        list.setCommandListener(this);
        return list;
    }

    public void commandAction(Command c, Displayable d) {
        int s = list.size();
        String msg = "item: ";
        for (int i = 0; i < s; i++) {
            if (list.isSelected(i)) {
                msg = msg + " :" + i;
            }
        }
        Alert alert = new Alert("My Alert", msg, null, AlertType.CONFIRMATION);
        display.setCurrent(alert, d);
    }
}

No comments: