J2ME相册
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.*;
/**
* @author Administrator
*/
public class ImageItemDemo extends MIDlet implements CommandListener{
private Display display;
private Form form;
private Command exit;
private Command next;
//声明存放图片的Image数组
private Image[] image;
//声明ImageItem组件
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数组
image=new Image[3];
//使用循环遍历的方式,通过对应的图片创建Image对象
for ( ;i<3;i++)
{
//System.out.println("/"+i+".png");
///0.png image[i]=Image.createImage("/"+i+".png");
image[i]=Image.createImage("/"+i+".png");
//image[i] = Image.createImage("/0.png");
//System.out.println("/"+i+".png");
}
imageItem=new ImageItem(null,image[0],ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER,"Logo 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 c, Displayable d) {
if (c==exit)
{
destroyApp(false);
notifyDestroyed();
}
else if (c==next)
{
if (i==3)
{
i=0;
}
imageItem.setImage(image[i]);
//System.out.println(i);
i++;
}
}
}
资源文件中增加0.png,1.png,2.png
浙公网安备 33010602011771号