10 Oct

Tutorial Java ME 2 – Part 4 Image Item

Contoh penggunaan ImageItem pada Form JavaME – J2ME

public class ImageItemDemo extends Form {

    public ImageItemDemo() {
        super("ImageItem Demo");
        try {
            Image img = Image.createImage("logo.png");
            
            ImageItem i1 = new ImageItem("Gambar", img, ImageItem.LAYOUT_CENTER, "");
            ImageItem i2 = new ImageItem("Gambar", img, ImageItem.LAYOUT_CENTER, "");
            
            append(i1);
            append(i2);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
}

10 Oct

Tutorial Java ME 2 – Part 2 Date Field

Contoh penggunaan DateField pada Form Java ME – J2ME

public class DateFieldDemo extends Form {

    public DateFieldDemo() {
        super("DateField Demo");
        
        DateField df1 = new DateField("DATE: ", DateField.DATE);
        DateField df2 = new DateField("TIME:", DateField.TIME);
        DateField df3 = new DateField("DATETIME:", DateField.DATE_TIME);
        
        append(df1);
        append(df2);
        append(df3);                
    }
    
}

10 Oct

Tutorial Java ME 2 – Part 1 – Choice Group

Contoh penggunaan Choice Group pada Form Java ME – J2ME

public class ChoiceGroupDemo extends Form {

    public ChoiceGroupDemo() {
        super("ChoiceGroup Demo");
        ChoiceGroup cg1 = new ChoiceGroup("EXCLUSIVE", ChoiceGroup.EXCLUSIVE);
        cg1.append("Pilihan 1", null);
        cg1.append("Pilihan 2", null);
        
        ChoiceGroup cg2 = new ChoiceGroup("MULTIPLE", ChoiceGroup.MULTIPLE);
        cg2.append("Pilihan 1", null);
        cg2.append("Pilihan 2", null);
        
        append(cg1);
        append(cg2);
    }
    
}

10 Oct

Tutorial Java ME – Part 5 Alert

Contoh penggunaan Alert di Java ME (J2ME):

public class TesGUI extends MIDlet implements CommandListener {
    private Display display;
    private Command cmdExit,cmdOK;
    private Form f;

public void startApp() {
        display = Display.getDisplay(this);
        
     cmdExit = new Command("Exit", Command.EXIT, 0);
     cmdOK = new Command("OK", Command.OK, 0);
        
        f = new Form("Judul Form");
        f.addCommand(cmdExit);
        f.addCommand(cmdOK);        
        f.setCommandListener(this);
        
        display.setCurrent(f);
}

public void commandAction(Command c, Displayable d)
{
        if (c == cmdExit) {
            destroyApp(true);
            notifyDestroyed();
        } else if (c == cmdOK) {
            Alert a = new Alert(
                	"Judul", "Isi Alert", null, 
				AlertType.INFO);
            display.setCurrent(a, f);
        }
}
}

Type-type ALERT:
ALARM
CONFIRMATION
ERROR
INFO
WARNING

Cara membuat alert bersifat MODAL (tidak menutup jika tidak ditekan OK)

Alert a = new Alert("Judul", "Isi Alert", 
	null, AlertType.INFO);
a.setTimeout(Alert.FOREVER);

10 Oct

Tutorial Java ME – Part 4 Command

Macam-macam Command pada Java ME (J2ME):
BACK = navigasi ke layar sebelumnya
CANCEL = jawaban negatif dari dialog
EXIT = keluar aplikasi
HELP = permintaan menampilkan help
ITEM = aksi pemilihan item tertentu
OK = jawaban positif dari dialog
SCREEN = command pada screen tertentu
STOP = menghentikan proses yang berjalan

Contoh Penggunaan Command pada Java ME (J2ME):

public class TesGUI extends MIDlet implements CommandListener {
    private Display display;
    private Command cmdExit;

    public void startApp() {
        display = Display.getDisplay(this);
        
        Form f = new Form("Judul Form");
        cmdExit = new Command("Exit", Command.EXIT, 1);
        f.addCommand(cmdExit);
        f.setCommandListener(this);
        
        display.setCurrent(f);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdExit) {
            destroyApp(true);
            notifyDestroyed();
        }
    }
}

Contoh Penggunaan CommandPriority pada Java ME (J2ME):

	private Command cmdExit,cmdOK,cmdBack,cmdCancel;

    public void startApp() {
        display = Display.getDisplay(this);
        
        Form f = new Form("Judul Form");
        cmdExit = new Command("Exit", Command.EXIT, 0);
        cmdOK = new Command("OK", Command.OK, 0);
        cmdBack = new Command("Back", Command.BACK, 0);
      cmdCancel = new Command("Cancel",Command.CANCEL, 0);

        f.addCommand(cmdExit);
        f.addCommand(cmdOK);
        f.addCommand(cmdBack);
        f.addCommand(cmdCancel);
        f.setCommandListener(this);
        
        display.setCurrent(f);
    }

10 Oct

Tutorial Java ME – Part 3 Example Ticker

Contoh penggunaan Ticker pada Java ME (J2ME) ditempelkan pada Form

public class TesGUI extends MIDlet {
    private Display display;

    public void startApp() {
        display = Display.getDisplay(this);
        
        Ticker ticker = new Ticker("Ini Teks Berjalan");
        
        Form f = new Form("Judul Form");
        f.setTicker(ticker);
        
        display.setCurrent(f);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}

Contoh penggunaan Ticker pada Java ME (J2ME) ditempelkan pada TextBox

public class TesGUI extends MIDlet {
    private Display display;

    public void startApp() {
        display = Display.getDisplay(this);
        
        Ticker ticker = new Ticker("Ini Teks Berjalan");
        
        TextBox t = new TextBox("Judul", "Isi Text", 100, TextField.ANY);
        t.setTicker(ticker);
        
        display.setCurrent(t);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}

Contoh penggunaan Ticker pada Java ME (J2ME) ditempelkan pada List

public class TesGUI extends MIDlet {
    private Display display;

    public void startApp() {
        display = Display.getDisplay(this);
        
        Ticker ticker = new Ticker("Ini Teks Berjalan");        
        List l = new List("Judul", List.MULTIPLE);
        l.append("Pilihan 1", null);
        l.append("Pilihan 2", null);
        l.append("Pilihan 3", null);        
        l.setTicker(ticker);
        
        display.setCurrent(l);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}

10 Oct

Tutorial Java ME – Part 2 Example List

Contoh penggunaan List pada Java ME (J2ME)

public class TesGUI extends MIDlet {
    private Display display;

    public void startApp() {
        display = Display.getDisplay(this);
                
        List l = new List("Judul", List.EXCLUSIVE); // IMPLICIT, MULTIPLE
        l.append("Pilihan 1", null);
        l.append("Pilihan 2", null);
        l.append("Pilihan 3", null);
        
        display.setCurrent(l);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}