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

ImageItem用法例题

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

package com.brj.test;

import java.io.IOException;

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.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
* ImageItem用法例题
*
* @author Administrator
*
*/
public class ImageItemTest extends MIDlet implements CommandListener {
private Display display;
private Command exit;
private Command showImages;// 转换图片
private Form mainFace;
private ImageItem image1;
private ImageItem image2;
private int flag;

public ImageItemTest() {
  display = Display.getDisplay(this);
  exit = new Command("Exit", Command.EXIT, 1);
  showImages = new Command("ShowImages", Command.SCREEN, 0);
  mainFace = new Form("");
  try {
   image1 = new ImageItem("", Image.createImage("/1.png"),
     Item.LAYOUT_TOP, "Not Found");
   image2 = new ImageItem("", Image.createImage("/2.png"),
     Item.LAYOUT_BOTTOM, "Not Found");
  } catch (IOException e) {
   e.printStackTrace();
  }
  flag = 1;
}

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(exit);
  mainFace.addCommand(showImages);
  mainFace.append(image1);
  mainFace.append(image2);
  mainFace.setCommandListener(this);
  display.setCurrent(mainFace);

}

public void commandAction(Command arg0, Displayable arg1) {
  if (arg0 == exit) {
   try {
    this.destroyApp(false);
   } catch (MIDletStateChangeException e) {
    e.printStackTrace();
   }
   this.notifyDestroyed();
  }
  if (arg0 == showImages) {
   try {
    image1.setImage(Image.createImage("/" + (flag + 1) + ".png"));
    image2.setImage(Image.createImage("/" + (flag + 2) + ".png"));
    display.setCurrent(mainFace);
   } catch (IOException e) {
    e.printStackTrace();
   }
   flag++;
   if (flag == 9) {
    flag = 1;
   }
  }
}
}


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