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;
}
}
}
}