-- 作者:admin
-- 发布时间:2008/9/22 22:58:35
-- 程序代码——带有图片的Alert
/* * Midlet.java * * Created on 2008年9月17日, 上午10:49 */
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.lcdui.Image; import javax.microedition.midlet.MIDlet;
/** * * @author Administrator * @version */ public class Exec extends MIDlet implements CommandListener { Display display = Display.getDisplay(this); Form form = new Form("表单"); Alert alert = new Alert("通知"); Command cmd1 = new Command("显示图片", Command.ITEM, 1); Command cmd2 = new Command("显示文字", Command.ITEM, 1); Command cmd3 = new Command("退出", Command.ITEM, 1); Image image = null;
public void startApp() { try { image = Image.createImage("/images/java.jpg"); } catch (Exception e) { System.out.println(e.getMessage()); } alert.setCommandListener(this);
form.addCommand(cmd1); form.setCommandListener(this); display.setCurrent(form); }
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command cmd, Displayable arg1) { if (cmd.equals(cmd1)) { alert.setType(AlertType.INFO); alert.setImage(image); alert.setString(null); alert.setTimeout(Alert.FOREVER); alert.addCommand(cmd2); display.setCurrent(alert); } else if (cmd.equals(cmd2)) { alert.setType(AlertType.INFO); alert.setImage(null); alert.setTimeout(5000); alert.setString("欢迎你"); alert.removeCommand(cmd2); alert.addCommand(cmd3); display.setCurrent(alert); System.out.println(2); } else if (cmd.equals(cmd3)) { alert.removeCommand(cmd3); display.setCurrent(form); } } }
[此贴子已经被作者于2010-12-12 18:27:29编辑过]
|