AlertTypeDemo.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.lcdui.*;
  2. import javax.microedition.midlet.MIDlet;
  3. public class AlertTypeDemo
  4.     extends MIDlet implements CommandListener{
  5.     private Command CMD_EXIT=new Command("Exit",Command.EXIT,1);
  6.     private Command CMD_INFO=new Command("INFO",Command.SCREEN,2);
  7.     private Command CMD_WARN=new Command("WARN",Command.SCREEN,3);
  8.     private Command CMD_ERROR=new Command("ERROR",Command.SCREEN,4);
  9.     private Command CMD_ALARM=new Command("ALARM",Command.SCREEN,5);
  10.     private Command CMD_CONF=new Command("CONFIRMATION",Command.SCREEN,6);
  11.     private Display display;
  12.     private Form mainForm;
  13.     private AlertType alertType;
  14.     public AlertTypeDemo() {
  15.      display = Display.getDisplay(this);
  16.         alertType = AlertType.ALARM;
  17.         mainForm = new Form("AlertType演示播放声音");
  18.         mainForm.addCommand(CMD_EXIT);
  19.         mainForm.addCommand(CMD_INFO);
  20.         mainForm.addCommand(CMD_WARN);
  21.         mainForm.addCommand(CMD_ERROR);
  22.         mainForm.addCommand(CMD_ALARM);
  23.         mainForm.addCommand(CMD_CONF);
  24.         mainForm.setCommandListener(this);   
  25.     }
  26.     protected void startApp() {
  27.         display.setCurrent(mainForm);
  28.     }
  29.     protected void destroyApp(boolean unconditional) {
  30.     }
  31.     protected void pauseApp() {
  32.     }
  33.     public void commandAction(Command c, Displayable s) {
  34. int priority = c.getPriority(); 
  35. switch(priority){
  36. case 2:alertType = AlertType.INFO;break;
  37. case 3:alertType = AlertType.WARNING;break;
  38. case 4:alertType = AlertType.ERROR;break;
  39. case 5:alertType = AlertType.ALARM;break;
  40. case 6: alertType = AlertType.CONFIRMATION;break;
  41. }
  42. if(alertType.playSound(display)){
  43.      mainForm.append("声音已经播放n");
  44. }
  45. if (c == CMD_EXIT){
  46.     destroyApp(false);
  47.     notifyDestroyed();
  48.         }
  49.     }
  50. }