J2ME学习笔记:Alert控件的使用【原创】

首先我们要知道:Alert是一个显示等待或错误信息的屏幕类,其构造方法如下:Alert(标题,初始内容,图像,类型)如Alert info = new Alert("Alert","This is a Alert Example!",img,AlertType.INFO);

以下给出一个代码:

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


public class Alert extends MIDlet implements CommandListener {

private Command exitCommand;
private Command alertCommand;
private TextBox tb;

public Alert()
{
   exitCommand = new Command("Exit",Command.EXIT,1);
   alertCommand = new Command("Alert",Command.SCREEN,1);
   tb = new TextBox("Terry","Alert Example",15,0);
   tb.addCommand(exitCommand);
   tb.addCommand(alertCommand);
   tb.setCommandListener(this);

   Display.getDisplay(this).setCurrent(tb);
}
   public Alert(String string, String string2, Image img, AlertType info) {
   // TODO Auto-generated constructor stub
}
protected void startApp() throws MIDletStateChangeException
    {
//   Display.getDisplay(this).setCurrent(tb);
  
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
  

}

protected void pauseApp()
{
  

}
public void commandAction(Command c, Displayable d) {
   //如果触发alertCommand按钮,则显示Alert屏幕
   if(d == tb && c == alertCommand){
    Image img;
    try{
     img = Image.createImage("/2.png");
    }
    catch(java.io.IOException e)
    {
     img = null;
     System.out.println("img is load...");
    }
    //创建一个Alert屏幕对象
    Alert info = new Alert("Alert","This is a Alert Example!",img,AlertType.INFO);
   
   }
  
  
}

 

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值