首页 | 联系我们 | 叶凡网络官方QQ群:323842844
游客,欢迎您! 请登录 免费注册 忘记密码
您所在的位置:首页 > 开发语言 > Java开发 > 正文

Alert用法的例子

作者:cocomyyz 来源: 日期:2013-07-25 02:14:16 人气:408 加入收藏 评论:0 标签:java j2me

package com.brj.test;

import java.io.IOException;

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.Image;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
* 重点练习Alert类
* @author brj
*
*/
public class TestAlert extends MIDlet implements CommandListener {
private Display display;
// the back face
private TextBox mainFace;
// the alert face
private Alert alert;
// exit Command button
private Command exitCommand;
// alert Command button
private Command alertCommand;

public TestAlert() {
  // get the instance of the Display
  display = Display.getDisplay(this);
  String mainFaceInstruction = "This is the place providing space to write!";
  mainFace = new TextBox("welcome", mainFaceInstruction, 100,
    TextField.ANY);
  // the Image of the alert
  Image alertImage = null;
  try {
   alertImage = Image.createImage("/gril.png");
  } catch (IOException e) {
   e.printStackTrace();
  }
  alert = new Alert("AlertTitle", "                      Sorry Error!",
    alertImage, AlertType.INFO);
  // set the timeout
  alert.setTimeout(Alert.FOREVER);
  // Command
  exitCommand = new Command("Exit", Command.EXIT, 1);
  alertCommand = new Command("Alert", Command.SCREEN, 0);

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
  // TODO Auto-generated method stub

}

protected void pauseApp() {
  // TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
  mainFace.addCommand(exitCommand);
  mainFace.addCommand(alertCommand);
  mainFace.setCommandListener(this);
  // set the Current Display
  display.setCurrent(mainFace);
}

public void commandAction(Command c, Displayable d) {
  // exit Command monitor
  if (c == exitCommand) {
   try {
    this.destroyApp(false);
   } catch (MIDletStateChangeException e) {
    e.printStackTrace();
   }
   this.notifyDestroyed();
  }

  // alert interphase
  if (c == alertCommand && d == mainFace) {
   display.setCurrent(alert, mainFace);
  }
}

}


本文网址:http://www.mingyangnet.com/html/java/127.html
读完这篇文章后,您心情如何?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
更多>>网友评论
发表评论
编辑推荐
  • 没有资料