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.Form; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class alertTest extends MIDlet implements CommandListener{ private Display display; public alertTest() { display = Display.getDisplay(this); } protected void startApp() throws MIDletStateChangeException { Form form = new Form("声音测试"); form.addCommand(new Command("警报",Command.SCREEN,1)); form.addCommand(new Command("确认",Command.SCREEN,1)); form.addCommand(new Command("错误",Command.SCREEN,1)); form.addCommand(new Command("提供信息",Command.SCREEN,1)); form.addCommand(new Command("警告",Command.SCREEN,1)); form.setCommandListener(this); display.setCurrent(form); } public void commandAction(Command arg0, Displayable arg1) { String cmd = arg0.getLabel(); if(cmd.equals("警报")){ display.setCurrent(new Alert("alarm","paipai,i love you.",null,AlertType.ALARM)); }else if(cmd.equals("确认")){ display.setCurrent(new Alert("confirmation","paipai is a nice girl.",null,AlertType.CONFIRMATION)); }else if(cmd.equals("错误")){ display.setCurrent(new Alert("error","paipai is beautiful.",null,AlertType.ERROR)); }else if(cmd.equals("提供信息")){ display.setCurrent(new Alert("info","paipai is preaty.",null,AlertType.INFO)); }else if(cmd.equals("警告")){ display.setCurrent(new Alert("warning","hello,wupaipai.",null,AlertType.WARNING)); } } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } }
转载于:https://www.cnblogs.com/chaohi/archive/2010/02/18/2330362.html