Building a J2ME sliding menu with text and images(part-1)

This example will show, how to create an image icon to perform the next action or next image from the list every time it's been clicked. So if you want to go from one icon to another icon by the nice sliding effect, you have to run the given example.

Building a J2ME sliding menu with text and images(part-1)

Building a J2ME sliding menu with text and images(part-1)

     

This example will show, how to create an image icon to perform the next action or next image from the list every time it's been clicked. So if you want to go from one icon to another icon by the nice sliding effect, you have to run the given example. For developing this application we have inherit canvass class and implement Runnable Interface. The Runnable interface is called from java.lang package and this interface has only one methods which is called: run() method. The function to run the application is as follows which is used in this application:

public void run(){
  try{
  while(true){
  repaint();
  synchronized(this){
  wait(100L);
  }
  }
  }catch(Exception e){
  e.printStackTrace();
  }
  }

And the following image is created in this application is as follows:

image[0] = Image.createImage("/bollywood-height.png");
image[1] = Image.createImage("/212229_1193669628.png");
image[2] = Image.createImage("/95936_50.png");
image[3] = Image.createImage("/shreya.png");
image[4] = Image.createImage("/Aishw.png");
image[5] = Image.createImage("/karishma.png");
image[6] = Image.createImage("/tmb_jiahkhannishabd.png");
image[7] = Image.createImage("/amisha.png");
image[8] = Image.createImage("/shilpashetty.png");
image[9] = Image.createImage("/priti.png");

The Sample of Application is as follows:

 

Source Code of SlideImage.java

 

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class SlideImage extends MIDlet{
  private Display display;

  public void startApp(){
  display = Display.getDisplay(this);
  display.setCurrent(new IconsCanvas())
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){
  notifyDestroyed();
  }
}

class IconsCanvas extends Canvas implements Runnable{
  SlideMenu menu = null;

  public IconsCanvas(){
  Image[] image = new Image[10]
  try{
  image[0= Image.createImage("/bollywood-height.png");
  image[1= Image.createImage("/212229_1193669628.png");
  image[2= Image.createImage("/95936_50.png");
  image[3= Image.createImage("/shreya.png");
  image[4= Image.createImage("/Aishw.png");
  image[5= Image.createImage("/karishma.png");
  image[6= Image.createImage("/tmb_jiahkhannishabd.png");
  image[7= Image.createImage("/amisha.png");
  image[8= Image.createImage("/shilpashetty.png");
  image[9= Image.createImage("/priti.png");
  
  menu = new SlideMenu(new String[]{"1""2""3""4"
 
"5""6""7""8""9""10"},  
  image,  getWidth
(),  getHeight());
  new Thread(this).start();
  }catch(Exception e){
  e.printStackTrace();
  }
  }

  protected void paint(Graphics g){
  menu.paint(g);
  }

  public void keyPressed(int key){
  int gameKey = getGameAction(key);
  if(gameKey == Canvas.RIGHT){
  menu.slideItem(1);
  }else if(gameKey == Canvas.LEFT){
  menu.slideItem(1);
  }
  }

  public void run(){
  try{
  while(true){
  repaint();
  synchronized(this){
  wait(100L);
  }
  }
  }catch(Exception e){
  e.printStackTrace();
  }
  }
}

Download Source Code