📄 imageitemdemo.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ImageItemDemo extends MIDlet
implements CommandListener
{
private Display display;
private Form form;
private Command exit;
private Command next;
private Image[] image;
private ImageItem imageItem;
private int i=0;
public ImageItemDemo()
{
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
next= new Command("Next",Command.ITEM,2);
form = new Form("汽车标志相册");
form.addCommand(exit);
form.addCommand(next);
form.setCommandListener(this);
try
{
image=new Image[6];
for(;i<6;i++)
{
image[i] = Image.createImage("/"+i+".png");
}
imageItem = new ImageItem(null, image[0],
ImageItem.LAYOUT_NEWLINE_BEFORE |
ImageItem.LAYOUT_CENTER |
ImageItem.LAYOUT_NEWLINE_AFTER, "My Image");
form.append(imageItem);
}
catch (java.io.IOException error)
{
Alert alert = new Alert("Error", "不能显示图片",
null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command command, Displayable Displayable)
{
if (command == exit)
{
destroyApp(false);
notifyDestroyed();
}
else if(command==next)
{
System.out.println(i);
if(i==6)
i=0;
imageItem.setImage(image[i]);
i++;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -