博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
J2ME学习笔记(3)--Alert类的学习
阅读量:4031 次
发布时间:2019-05-24

本文共 2059 字,大约阅读时间需要 6 分钟。

Alert类的学习 

  Alert类用来给用户发出警告信息,但内容和类型不一定是警告性质的.可以把Alert认为是一个提供信息的对话框,其类型有:警告,错误,通知,确认等,显不Alert时用户界面会失去焦点.Alert可以自动定时解除,也可以设定一直保持在屏幕上让用户手动解除,(setTimeout(Alert.FOREVER)),解除后应用程序会继续下一个屏幕.

  Alert类常用方法

  

类型 方法 说明
void addCommand(Command cmd) 增加命令项
int getDefaultTimeout() 获取默认的Alert解除时间
Image getImage() 获取Alert图标
Gauage getIndicator() 获取Alert的活动指示器
String getString() 获取Alert内的文本内容
int getTimeout() 获取Alert的解除时间
AlertType getType() 获取Alert的类型
void removeCommand(Command com) 移除命令项
void setImage(Image img) 设置Alert图标
void setIndicator(Gauge indicator) 设置Alert指标器
void setString(String str) 设置Alert显示内容
void setTimeout(int time) 设置Alert解除时间
void setType(AlerType type) 设置Alert类型
void setCommandListener(Command listener) 设置鉴听者

Alert构造函数

new Alert(String str)   / new Alert(String title, String alertText, Image alertImage, AlertType alertType)

AlertType定义字段
类型 字段 说明
static AlertType ALARM 向用户警告一个事件
static AlertType CONFIRMATION 用来确认一个用户动作
static AlertType ERROR 向用户警告一个错误操作
static AlertType INFO 向用户提供一条一般性信息
static AlertType WARING 向用户警告一个危险操作

一个简单的例子

package demo;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ExampleDemo extends MIDlet implements CommandListener

{
 private Display display;
 private Form form;
 private Alert alert;
 private Command exit;
 private Command show;

 public ExampleDemo()

 {
  display = Display.getDisplay(this);
  form = new Form("Alert 的例子");
  alert = new Alert("Alert的标题","Alert里边的文字",null,AlertType.INFO);//设置一个Alert对象
  alert.setTimeout(Alert.FOREVER);/*正如Alert.FOREVER字面意思一样Alet不会自动消失
  ,当用户按了done时*/
  exit = new Command("退出" , Command.EXIT, 1);//退出命令
  show = new Command("显示" , Command.SCREEN,1);//显示Alert的命令
  form.addCommand(exit);
  form.addCommand(show);
  form.setCommandListener(this);
 }
 public void startApp()
 {
  display.setCurrent(form);
 }

 public void pauseApp()

 {
 }

 public void destroyApp(boolean condition)

 {

 }

 public void commandAction(Command command ,Displayable displayable)

 {
  if(command == exit)
  {
   destroyApp(true);
   notifyDestroyed();
  }
  if(command == show)
  {
   display.setCurrent(alert,form);
   
  }

 }

}

转载地址:http://cymbi.baihongyu.com/

你可能感兴趣的文章
最简单的使用redis自带程序实现c程序远程访问redis服务
查看>>
redis学习总结-- 内部数据 字符串 链表 字典 跳跃表
查看>>
iOS 对象序列化与反序列化
查看>>
iOS 序列化与反序列化(runtime) 01
查看>>
iOS AFN 3.0版本前后区别 01
查看>>
iOS ASI和AFN有什么区别
查看>>
iOS QQ侧滑菜单(高仿)
查看>>
iOS 扫一扫功能开发
查看>>
iOS app之间的跳转以及传参数
查看>>
iOS __block和__weak的区别
查看>>
Android(三)数据存储之XML解析技术
查看>>
Spring JTA应用之JOTM配置
查看>>
spring JdbcTemplate 的若干问题
查看>>
Servlet和JSP的线程安全问题
查看>>
GBK编码下jQuery Ajax中文乱码终极暴力解决方案
查看>>
jQuery性能优化指南
查看>>
Oracle 物化视图
查看>>
Multi-Task Networks With Universe, Group, and Task Feature Learning-阅读笔记
查看>>
A Survey of Zero-Shot Learning: Settings, Methods, and Applications-阅读笔记
查看>>
Cross-Domain Review Helpfulness Prediction -论文阅读
查看>>