Pengikut

Rabu, 29 April 2009

Simple Alert with Image and Default Warning Sound

FirstAlert.java

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

public class FirstAlert extends MIDlet implements CommandListener{
 Display display;
 List list;
 Image img;
 Alert alAl, alCo, alEr, alIn, alWa;
 Command cmExit;

 public FirstAlert() {
  display = Display.getDisplay(this);
  try {
  img = Image.createImage("/img.png");
  } catch (java.io.IOException e) {
  }
  cmExit = new Command("Exit", Command.EXIT, 1);
  list = new List("First Alert", List.IMPLICIT);
  list.append("ALARM", img);
  list.append("CONFIRMATION", img);
  list.append("ERROR", img);
  list.append("INFO", img);
  list.append("WARNING", img);
  list.addCommand(cmExit);
  list.setCommandListener(this);
  display.setCurrent(list);

  alAl = new Alert("ALARM", "Alert ALARM", null, AlertType.ALARM);
  alAl.setTimeout(Alert.FOREVER);

  alCo = new Alert("CONFIRMATION", "Alert CONFIRMATION", null, AlertType.CONFIRMATION);
  alCo.setTimeout(Alert.FOREVER);

  alEr = new Alert("ERROR", "Alert ERROR", null, AlertType.ERROR);
  alEr.setTimeout(Alert.FOREVER);

  alIn = new Alert("INFO", "Alert INFO", null, AlertType.INFO);
  alIn.setTimeout(Alert.FOREVER);

  alWa = new Alert("WARNING", "Alert WARNING", null, AlertType.WARNING);
  alWa.setTimeout(Alert.FOREVER);
 }

 public void startApp() {
 }

 public void pauseApp() {
 }

 public void destroyApp(boolean unconditional) {
 }

 public void commandAction(Command c, Displayable s){
  if (c == List.SELECT_COMMAND){
  switch (list.getSelectedIndex()){
  case 0:
  display.setCurrent(alAl);
  break;
  case 1:
  display.setCurrent(alCo, list);
  break;
  case 2:
  display.setCurrent(alEr);
  break;
  case 3:
  display.setCurrent(alIn, list);
  break;
  case 4:
  display.setCurrent(alWa);
  break;
  }
  }else if(c == cmExit){
  exitMIDlet();
  }
 }

 public void exitMIDlet() {
  destroyApp(false);
  notifyDestroyed();
 }
};



This project requires an image with the name "img.png" with size 15 x 15 pixels

Tidak ada komentar:

Posting Komentar

 

© Copyright by See Complete Code | Template by BloggerTemplates | Blog vio at Blog-HowToTricks