Minggu, 29 Mei 2011

Penggunaan Alert Pada Mobile

Ada beberapa Alert pada mobile , seperti :
alert alarm
alert confirmation
alert info
alert warning
alert error
alert modal

dan inilah contoh scriptnya :

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

public class penggunaanAlert extends MIDlet implements CommandListener
{
    Display display;
    Form mainForm;
    Command exitCommand = new Command("Exit", Command.EXIT,0);
    Command okCommand = new Command("Exit", Command.OK,0);
    Gauge gauge = new Gauge(null,false,5,0);
    Command[] commands =
    {
        new Command("Alarm",Command.OK,0),
        new Command("Confirmation",Command.OK,0),
        new Command("Info",Command.OK,0),
        new Command("Warning",Command.OK,0),
        new Command("Error",Command.OK,0),
        new Command("Modal",Command.OK,0),
    };
    Alert[] alert={
      new Alert("Alarm Alert",
              "Example of an ALARM type of Alert",
              null,AlertType.ALARM),
      new Alert("Confirmation Alert",
              "Example of an CONFIRMATION type of Alert",
              null,AlertType.CONFIRMATION),
      new Alert("Info Alert",
              "Example of an INFO type of Alert",
              null,AlertType.INFO),
      new Alert("Warning Alert",
              "Example of an WARNING type of Alert,w/ gauge indicator",
              null,AlertType.WARNING),
      new Alert("Error Alert",
              "Example of an ERROR type of Alert,w/ an 'OK' Command",
              null,AlertType.ERROR),
      new Alert("Modal Alert",
              "Example of an MODAL type of Alert: timeout = FOREVER",
              null,AlertType.ERROR),
    };

    public penggunaanAlert()
    {
     mainForm = new Form("JEDI : Alert Example");
     mainForm.addCommand(exitCommand);
     for(int i=0; i<commands.length; i++){
         mainForm.addCommand(commands[i]);
     }
     mainForm.setCommandListener(this);
     //Menambah sebuah gauge dan menge-set timeout(milliseconds)
     alert[3].setIndicator(gauge);
     alert[3].setTimeout(5000);
     //Menambah sebuah command untuk alert
     alert[4].addCommand(okCommand);
     //Menge-set alert
     alert[5].setTimeout(Alert.FOREVER);
    }
    public void startApp()
    {
        if (display == null){
            display= Display.getDisplay(this);
            display.setCurrent(mainForm);
        }
    }

    public void pauseApp() {

    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d)
    {
     if(c == exitCommand){
         destroyApp(true);
         notifyDestroyed();//Exit
     }
     for(int i=0; i<commands.length; i++){
         if(c == commands[i]){
             display.setCurrent(alert[i]);
         }
     }
    }
}

maka tampilannya akan seperti ini :


 

Tidak ada komentar:

Posting Komentar