Home J2me J2ME Label Example



J2ME Label Example
Posted on: December 1, 2008 at 12:00 AM
This is the simple create label example in which we create an StringItem to display the "UserId" as a label text.

J2ME Label Example

     

This is the simple create label example in which we create an StringItem to display the "UserId" as a label text. In the given application we are using setLabel to set the new label to the ItemString. We are replacing the new label on the place of previous label and setText on the position on the previous text. The complete source code is given below and the screenshot of the application given below for easy to understand. 

 

 

 

 

The Application is as follows:

 

 

LabelMIDlet.java

 

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

public class LabelMIDlet extends MIDlet implements CommandListener{
  private Display display; 
  private Form form; 
  private StringItem item; 
  private Command next, exit; 
  
  public LabelMIDlet(){
  display = Display.getDisplay(this);  
  form = new Form("Label Text")
  item = new StringItem("UserId: ""sandeep15284@rediffmail.com");
  next = new Command("Next", Command.SCREEN, 1);
  exit = new Command("Exit", Command.EXIT, 1);
  form.addCommand(exit);
  form.addCommand(next);  
  form.append(item);
  form.setCommandListener(this)
  }

  public void startApp(){  
  display.setCurrent(form);
  }

  public void pauseApp(){ }

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

  public void commandAction(Command c, Displayable s){
  String label = c.getLabel();
  if (label.equals("Next")){
  item.setLabel("E-MAIL ID: ");
  item.setText("sandeep15284@rediffmail.com")
  form.removeCommand(next);
  else if (label.equals("Exit")) {
  destroyApp(true);
  
  }
}

 

Download Source Code

Related Tags for J2ME Label Example:
cstringgittextuserdisplaylabelthisidsimplecreatetexexampletoexamexteititemspluseiminasmplaytrispemuseridxawhichxampsspatismpleastrsimxtssriringthstababeldisppleplo


More Tutorials from this section

Ask Questions?    Discuss: J2ME Label Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.