使用J2ME的幻灯片

时间:2018-08-26 11:57:00

标签: java java-me

我希望这段代码可以用于幻灯片放映。但是它只显示最后一张图像。谁能解释出什么问题了吗?

    public class Midlet extends MIDlet implements CommandListener {

String file[] 
{"/logo.png","/logo1.png","/logo2.png","/logo3.png","/logo4.png"}; 
public Midlet() throws IOException 
{
        display = Display.getDisplay(this);
        form=new Form("SlideShow");
        start=new Command("Start",Command.OK,1);
        form.addCommand(start);
        form.setCommandListener(this);

}
public void startApp() {
    display.setCurrent(form);
}

public void commandAction(Command c, Displayable d) {
    if(c==start)
    {


    try {
            for(int i=0;i<5;i++)
            {
            img[i]=Image.createImage(file[i]);
            imageItem[i] = new ImageItem("Muruga",img[i] , 
ImageItem.LAYOUT_CENTER, "image not found");
            form1[i]=new Form("Images");
            form1[i].append(imageItem[i]);
            form1[i].setCommandListener(this);
            display.setCurrent(form1[i]);
            }

由于图像应该静止了几秒钟,所以我使用了System.currentTimeMillis()方法

            for(int i=0;i<5;i++)
            {
            System.out.println(i+1);
            display.setCurrent(form1[i]);
            long milli=System.currentTimeMillis();
            while(System.currentTimeMillis()<=milli+1000)
            {
                display.setCurrent(form1[i]);

            }
            if(i==4)
                destroyApp(true);
            }
        } catch (IOException ex) {
            System.out.println("Not found");
        }
    }
}
}

0 个答案:

没有答案