Mega Code Archive

 
Categories / Java Tutorial / J2ME
 

Alarm alert, confirmation alert, error alert, info alert, warning alert

import java.io.IOException; 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.TextBox; import javax.microedition.lcdui.TextField; import javax.microedition.midlet.MIDlet; public class FewAlertsMIDlet extends MIDlet implements CommandListener {   private Command exitCommand = new Command("exit", Command.SCREEN, 1);   private Command alarmCommand = new Command("alarm", Command.SCREEN, 2);   private Command confirmCommand= new Command("confirm", Command.SCREEN, 2);   private Command errorCommand = new Command("error", Command.SCREEN, 2);   private Command infoCommand = new Command("info", Command.SCREEN, 2);   private Command warningCommand = new Command("warning", Command.SCREEN, 2);   private Alert alarmAlert = new Alert("alarm",null,null,  AlertType.ALARM);   private Alert confirmAlert = new Alert("confirm", null,null, AlertType.CONFIRMATION);   private Alert errorAlert = new Alert("error", null, null,AlertType.ERROR); //  private Alert infoAlert = new Alert("info", null,infoImage, AlertType.INFO);   private Alert warningAlert = new Alert("warning",null, null, AlertType.WARNING);   private Display display = Display.getDisplay(this);   public FewAlertsMIDlet() {   }   public void startApp() {     TextBox main = new TextBox("","",26,TextField.ANY);     Image infoImage = null;     try {       infoImage = Image.createImage("/a.png");     } catch (IOException e) {     }     alarmAlert.setTimeout(Alert.FOREVER);     confirmAlert.setTimeout(3000);     errorAlert.setTimeout(3000);   //  infoAlert.setTimeout(3000);     warningAlert.setTimeout(3000);     main.addCommand(exitCommand);     main.addCommand(alarmCommand);     main.addCommand(confirmCommand);     main.addCommand(errorCommand);     main.addCommand(infoCommand);     main.addCommand(warningCommand);     main.setCommandListener(this);     display.setCurrent(main);   }   public void pauseApp() {   }   public void destroyApp(boolean unconditional) {   }   public void commandAction(Command c, Displayable s) {     if (c == exitCommand) {       destroyApp(false);       notifyDestroyed();     }     if (c == alarmCommand) {       display.setCurrent(alarmAlert);     }     if (c == confirmCommand) {       display.setCurrent(confirmAlert);     }     if (c == errorCommand) {       display.setCurrent(errorAlert);     }  //   if (c == infoCommand) {    //   display.setCurrent(infoAlert);    // }     if (c == warningCommand) {       display.setCurrent(warningAlert);     }   } }