AlertTypeDemo.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.MIDlet;
- public class AlertTypeDemo
- extends MIDlet implements CommandListener{
- private Command CMD_EXIT=new Command("Exit",Command.EXIT,1);
- private Command CMD_INFO=new Command("INFO",Command.SCREEN,2);
- private Command CMD_WARN=new Command("WARN",Command.SCREEN,3);
- private Command CMD_ERROR=new Command("ERROR",Command.SCREEN,4);
- private Command CMD_ALARM=new Command("ALARM",Command.SCREEN,5);
- private Command CMD_CONF=new Command("CONFIRMATION",Command.SCREEN,6);
- private Display display;
- private Form mainForm;
- private AlertType alertType;
- public AlertTypeDemo() {
- display = Display.getDisplay(this);
- alertType = AlertType.ALARM;
- mainForm = new Form("AlertType演示播放声音");
- mainForm.addCommand(CMD_EXIT);
- mainForm.addCommand(CMD_INFO);
- mainForm.addCommand(CMD_WARN);
- mainForm.addCommand(CMD_ERROR);
- mainForm.addCommand(CMD_ALARM);
- mainForm.addCommand(CMD_CONF);
- mainForm.setCommandListener(this);
- }
- protected void startApp() {
- display.setCurrent(mainForm);
- }
- protected void destroyApp(boolean unconditional) {
- }
- protected void pauseApp() {
- }
- public void commandAction(Command c, Displayable s) {
- int priority = c.getPriority();
- switch(priority){
- case 2:alertType = AlertType.INFO;break;
- case 3:alertType = AlertType.WARNING;break;
- case 4:alertType = AlertType.ERROR;break;
- case 5:alertType = AlertType.ALARM;break;
- case 6: alertType = AlertType.CONFIRMATION;break;
- }
- if(alertType.playSound(display)){
- mainForm.append("声音已经播放n");
- }
- if (c == CMD_EXIT){
- destroyApp(false);
- notifyDestroyed();
- }
- }
- }