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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
List in J2ME 
 

J2ME Canvas List Example will explain you, how to create list of items. In this example we are going to create a simple list of text, that will show the selected item on the same screen.

 

List in J2ME

                         

J2ME Canvas List Example will explain you, how to create list of items. In this example we are going to create a simple list of text, that will show the selected item on the same screen. In the example you can see that we have created a class and then a constructor of the same class. In the constructor we defined the list and added some items into it..

 

 

 

 

Syntax for creating a list

  public CanvasListExample() {
    canvas = new CanvasList();
    list = new List("Employee List", Choice.IMPLICIT);
    show = new Command("Show", Command.OK, 1);
    list.append("Miss. Anusmita"null);
    list.append("Miss. Neelam"null);
    list.append("Mr. Sandeep"null);
    list.append("Mr. Suman"null);
    list.append("Mr. Saurabh"null);
    list.addCommand(show);
    display = Display.getDisplay(this);
  }

You can add any number of elements into it using list.append ()

The simple list application will look like as follow..

List in J2ME

 

 

Source Code of CanvasListExample.java

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

public class CanvasListExample extends MIDlet implements CommandListener{
  private Display display;
  private CanvasList canvas;
  private List list;
  private Command show;

  public CanvasListExample() {
    canvas = new CanvasList();
    list = new List("Employee List", Choice.IMPLICIT);
    show = new Command("Show", Command.OK, 1);
    list.append("Miss. Anusmita"null);
    list.append("Miss. Neelam"null);
    list.append("Mr. Sandeep"null);
    list.append("Mr. Suman"null);
    list.append("Mr. Saurabh"null);
    list.addCommand(show);
    display = Display.getDisplay(this);
  }

  public void startApp(){
    list.setCommandListener(this);
    display.setCurrent(list);
  }

  public void pauseApp() {}

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

  public void commandAction(Command c, Displayable d){
    String label = c.getLabel();
    if(label.equals("Show")){
      display.setCurrent(canvas);
    }
  }
  class CanvasList extends Canvas implements CommandListener{
    private Image image;
    private Command back;

    public CanvasList(){
      back = new Command "Back", Command.BACK, 1);
      addCommand (back);
      setCommandListener (this);
    }

    public void paint(Graphics g){
      int width = getWidth();
      int height = getHeight();
      String str = list.getString(list.getSelectedIndex());

      g.setColor(00255);
      g.drawString(str, width/2, height/2, Graphics.HCENTER | Graphics.TOP);
    }

    public void commandAction(Command c, Displayable d){
      String label = c.getLabel();      
      if(label.equals("Back")){
        display.setCurrent(list);
      }
    }
  }
}

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 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

hi,

this code is working fine in emulator, but when i m installing it in my nokia N73 mobile, i m getting error,like:"application not compatible with this phone".

Can ayone help me how to solve this.
thanx.

Posted by Satish on Tuesday, 12.9.08 @ 07:32am | #82560

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.