J2ME - Contoh Alert




J2ME - Contoh Membuat Alert Pada HP

Kali ini saya coba membuat Kodingan tentang membuat Alert pada J2ME

Gambar Di atas adalah Tampilan Akhirnya

dan ini adalah Kodingannya



===========================================

package awal;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.*;

/**
 * @author Yandi
 */
public class Contoh_Alert extends MIDlet implements CommandListener {

    private List menuUtama;
    private Alert alert;
    private Command cmdExit;
    private Command cmdBack;
    private Display tampilkan;
    private Ticker promosi;
    private Image imgAlert;

    public void startApp() {
        promosi = new Ticker("Selamat Datang di Blog http://www.yandywoody.blogspot.com");

        menuUtama = new List("Menu Utama", List.IMPLICIT);
        menuUtama.append("alert1", null);
        menuUtama.append("alert2", null);
        menuUtama.append("alert3", null);
        menuUtama.append("Exit", null);

        menuUtama.setTicker(promosi);
        menuUtama.setCommandListener(this);

        tampilkan = Display.getDisplay(this);
        tampilkan.setCurrent(menuUtama);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        try {
            imgAlert = Image.createImage("/tileset/65.png");
        } catch (Exception e) {
        }

        if (d == menuUtama) {
            if (menuUtama.isSelected(0)) {

                alert = new Alert("Alert Tipe 1");
                tampilkan.setCurrent(alert);

            } else if (menuUtama.isSelected(1)) {

                alert = new Alert("Warning", "Alert Tipe 2", null, AlertType.WARNING);
                tampilkan.setCurrent(alert);

            } else if (menuUtama.isSelected(2)) {

                alert = new Alert("Attention", "Alert Tipe 3", imgAlert, AlertType.INFO);
                tampilkan.setCurrent(alert);

            } else if (menuUtama.isSelected(3)) {
                notifyDestroyed();
                destroyApp(true);
            }
        } else if (c == cmdBack) {
            tampilkan.setCurrent(menuUtama);
        }
    }
}


==========================================================

selamat Mencoba

No comments:

Post a Comment

Pages