Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Building a J2ME sliding menu with text and images(part-2) 
 

In the given J2ME Menus example, we have explained to create two different buttons that is going to perform as a back and forward buttons. You can see the series of photographs one by one using these sliding menu in J2ME.

 

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

                         

In the given J2ME Menus example, we have explained to create two different buttons that is going to perform as a back and forward buttons. You can see the series of photographs one by one using these sliding menu in J2ME.

Code to create back and forward button images in J2ME

 

 

 

 

r_arrow = Image.createImage("/slide_arrow_right.png");

l_arrow = Image.createImage("/slide_arrow_left.png");

To change the image as per our next event, we have created a function as given below:

public void slideItem(int next){
    if(!isImage() && select_index + next >= && select_index + next < labels.length){
      back_index = select_index;      
      select_index += next;      
      time = System.currentTimeMillis();
    }
  }

 The Application is as follows:

 

 

Source Code of SlideMenu.java

 

import javax.microedition.lcdui.*;

public class SlideMenu{
  public int select_index, back_index, width, height;
  public Image r_arrow, l_arrow;
  String[] labels = null;
  Image[] icons = null;
  public int duration = 500;
  long time = 0;
  
  public SlideMenu(String[] labels, Image[] icons, int width, 
         int 
heightthrows Exception{
    try{
      r_arrow = Image.createImage("/slide_arrow_right.png");
      l_arrow = Image.createImage("/slide_arrow_left.png");
    }catch(Exception e){
      e.printStackTrace();
    }
    this.width = width;
    this.height = height;    
    this.labels = labels;
    this.icons = icons;    
  }

  public void slideItem(int next){
    if(!isImage() && select_index + next >= && select_index + 
        next < labels.length
){

      back_index = select_index;      
      select_index += next;      
      time = System.currentTimeMillis();
    }
  }

  public boolean isImage(){
    return back_index != select_index;
  }

  public void paint(Graphics g){  
    g.setColor(25500);
    g.fillRect(00, width, height);    
    g.setColor(00255);
    
    if(select_index > 0){
      g.drawImage(l_arrow, 2, height / 2
      Graphics.LEFT | Graphics.VCENTER
);
    }

    if(select_index < icons.length - 1){
      g.drawImage(r_arrow, width - 2, height / 2
      Graphics.RIGHT | Graphics.VCENTER
);
    }

    g.drawString(labels[select_index], width / 2
    height - 
2, Graphics.BOTTOM | Graphics.HCENTER);    

    g.setClip(l_arrow.getWidth()0, width - 
    l_arrow.getWidth
(), height);
    
    if(select_index != back_index){
      int difference = (int)(System.currentTimeMillis() - time);      
      if(difference > duration){
        difference = duration;
      }
      
      int image_present = select_index > back_index ? : - 1;
      int current_image = width / - image_present * 
      difference * width / duration;

      int next_image = current_image + width * image_present;
      
      g.drawImage(icons[back_index], current_image, height / 2
      Graphics.VCENTER | Graphics.HCENTER
);      

      g.drawImage(icons[select_index], next_image, height / 2
      Graphics.VCENTER | Graphics.HCENTER
);
      
      if(difference >= duration){
        back_index = select_index;
      }
    }else{
      g.drawImage(icons[select_index], width / 2, height / 2
      Graphics.VCENTER | Graphics.HCENTER
);
    }
  }
}

Download Source Code

                         

» View all related tutorials
Related Tags: c file list table time hash mobile object map screen hashtable maps display key value this id keys oo wav

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.