4

I have tried with image slideshow in j2me. Below is my code for image slideshow. But will it execute image don't slideshow and not displayed.

If I click play button then image will slideshow automatically from image 0.jpg until image 7.jpg.

this variable for slide

 String[] Foto={"/0.jpg", "/1.jpg","/2.jpg", "/3.jpg","/4.jpg", "/5.jpg","/6.jpg", "/7.jpg"};
 Image[] img = new Image[8];

and this loop for showing image..

protected void paint(Graphics g) {
    try {

        g.setColor(255, 0, 0 );
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(255,0, 0);
        g.drawString(text,getWidth()/2, getHeight()/2,
        Graphics.TOP | Graphics.HCENTER);
        g.setColor(0, 255, 0);
        g.setColor(123,0,255);
        g.drawRect(74,74, 100,100 );
        g.drawRect(72,72, 104,104 );

                   for ( int i=0;i<8;i++)
                if (i==1)
                if (i==2)
           img[i]=Image.createImage(Foto[i]);
           g.drawImage(img [1],124,124, Graphics.VCENTER | Graphics.HCENTER );
           g.drawImage(img [2],124,124, Graphics.VCENTER | Graphics.HCENTER );
           g.drawImage(img [1],124,124, Graphics.VCENTER | Graphics.HCENTER );

    } catch (IOException ex) {
        ex.printStackTrace();
    }}
gnat
  • 6,213
  • 108
  • 53
  • 73
  • Try putting all this outside outside the paint function. for(int i=0;i<8;i++) { img[i] = Image.createImage(Foto[i]); } And delete the lines inside the paint that does the same. – mr_lou Nov 26 '12 at 14:16

1 Answers1

0

You have a loop in Paint(), it will paint one by one image on canvas. Try a Global variable currentIndex = 0

protected void paint(Graphics g) {
try {

    g.setColor(255, 0, 0 );
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(255,0, 0);
    g.drawString(text,getWidth()/2, getHeight()/2,
    Graphics.TOP | Graphics.HCENTER);
    g.setColor(0, 255, 0);
    g.setColor(123,0,255);
    g.drawRect(74,74, 100,100 );
    g.drawRect(72,72, 104,104 );


   img = Image.createImage(Foto[currentIndex]);
   g.drawImage(img,124,124, Graphics.VCENTER | Graphics.HCENTER );

} catch (IOException ex) {
    ex.printStackTrace();
}}

onClick your button, your can try

currentIndex++;
repaint();

If you want a animation, you can change x or y when your repaint image

NDM
  • 6,731
  • 3
  • 39
  • 52
Thanh Le
  • 763
  • 4
  • 13