J2ME image slide show

I tried with image slide show in j2me. Below is the code for the image slide show. But whether he will execute the image, and not show the slide show and not be displayed.

If I press the play button, then the image will be a slide show automatically from image 0.jpg to image 7.jpg.

this variable for the 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 cycle to display the 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(); }} 
+4
source share
1 answer

You have a loop in Paint (), it will draw one image per canvas. Try the 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(); }} 

onPress the button, you can try

 currentIndex++; repaint(); 

If you need animation, you can change x or y when your redraw image

0
source

All Articles