import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ImageItemDemo extends MIDlet implements ItemCommandListener {
private Display display;
public ImageItemDemo(){
display = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Image img = null;
try {
img = Image.createImage("/Icon.png");
} catch (IOException e) {
e.printStackTrace();
}
Form f = new Form("ImageItem测试");
f.append(img);
ImageItem ii1 = new ImageItem("",img,Item.LAYOUT_CENTER|Item.LAYOUT_NEWLINE_AFTER,"图片1取代文字",Item.BUTTON);
f.append(ii1);
ImageItem ii2 = new ImageItem("",img,Item.LAYOUT_RIGHT|Item.LAYOUT_NEWLINE_BEFORE,"图片2取代文字",Item.HYPERLINK);
f.append(ii2);
display.setCurrent(f);
}
public void commandAction(Command c, Item d) {
System.out.println(c.getLabel());
System.out.println(d.getLabel());
}
}
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ImageItemDemo extends MIDlet implements ItemCommandListener {
private Display display;
public ImageItemDemo(){
display = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Image img = null;
try {
img = Image.createImage("/Icon.png");
} catch (IOException e) {
e.printStackTrace();
}
Form f = new Form("ImageItem测试");
f.append(img);
ImageItem ii1 = new ImageItem("",img,Item.LAYOUT_CENTER|Item.LAYOUT_NEWLINE_AFTER,"图片1取代文字",Item.BUTTON);
f.append(ii1);
ImageItem ii2 = new ImageItem("",img,Item.LAYOUT_RIGHT|Item.LAYOUT_NEWLINE_BEFORE,"图片2取代文字",Item.HYPERLINK);
f.append(ii2);
display.setCurrent(f);
}
public void commandAction(Command c, Item d) {
System.out.println(c.getLabel());
System.out.println(d.getLabel());
}
}