课外天地 李树青学习天地JavaME移动开发课件 → 程序代码——带有图片的Alert


  共有15137人关注过本帖树形打印复制链接

主题:程序代码——带有图片的Alert

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1949 积分:26803 威望:0 精华:34 注册:2003/12/30 16:34:32
程序代码——带有图片的Alert  发帖心情 Post By:2008/9/22 22:58:35 [只看该作者]

/*
* 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编辑过]

 回到顶部