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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
J2ME Icon MIDlet Example 
 

In this example we are going to create icon list of different sizes. We are creating here a IconList class, in this class we inherited the property of List class.

 

J2ME Icon MIDlet Example

                         

In this example we are going to create icon list of different sizes. We are creating here a IconList class, in this class we inherited the property of List class. Then we are creating the constructor of IconList class on the basis of this predefined constructure.

List(String title, int listType, String[] stringElements, Image[] imageElements)

In this constructor we Creates a new List, specifying with its title, the type of the List, an array of string element and an array of image element.

In the Icon MIDlet class we are creating five images with its label. The Application is as follows:

 

 

 

 

 

IconMIDlet.java

 
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.IOException;

public class IconMIDlet extends MIDlet{
  private Display display;
  private IconList iconList;    
  private Image icon16x16, icon18x18, icon20x20, icon22x22, icon32x32;    
  private String[] label = {"16x16 pixels""18x18 pixels""20x20 pixels"
      "22x22 pixels""32x32 pixels"};
      
  public IconMIDlet(){
    try{
      icon16x16 = Image.createImage("/16.png");
      icon18x18 = Image.createImage("/18.png");
      icon20x20 = Image.createImage("/20.png");
      icon22x22 = Image.createImage("/22.png");
      icon32x32 = Image.createImage("/32.png");
    }catch (IOException ioe){
      ioe.printStackTrace();
    }
  }
  
  protected void startApp(){        
    Image[] listIcon = {icon16x16, icon18x18, icon20x20, icon22x22, icon32x32};      
    iconList = new IconList("IconList", List.IMPLICIT, label, listIcon, this);
    iconList.setFitPolicy(List.TEXT_WRAP_OFF);    
    display = Display.getDisplay(this);
    display.setCurrent(iconList);
  }

  protected void pauseApp(){}

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

class IconList extends List implements CommandListener{
  private IconMIDlet midlet;
  private Command exit;
  
  public IconList(String title, int type, String[] elements, Image[]
      
images, IconMIDlet midlet){
    super(title, type);
    this.midlet = midlet;
    for (int i = 0; i < elements.length; i++) {
      this.append(elements[i], images[i]);
    }
    exit = new Command("Exit", Command.EXIT, 1);
    this.addCommand(exit);
    this.setCommandListener(this);
  }

  public void commandAction(Command c, Displayable d){
    if (c == exit) {
      midlet.destroyApp(true);
    }
  }
}

Download Source Code

                         

» View all related tutorials
Related Tags: c j2me diff types type if example to rectangle draw exam raw angle e il pe in different m nt

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.