Home J2me J2ME Form Class



J2ME Form Class
Posted on: November 20, 2008 at 12:00 AM
In this J2ME Extends Form example, we are going to discuss about form, extending form in our class and appending values to it.

J2ME Form Class

     

In this J2ME Extends Form example, we are going to discuss about form, extending form in our class and appending values to it. But first of all lets discuss about form. In general, a form is a screen and this screen can contain any type of items such as images, text and text fields to get or show values to users. 

We can also set values into these forms using following syntax?

public int append(Item item)

The forgoing syntax can be used to add items into form in J2ME.

The application will look like as follow...

J2ME form class, append item example

In this image, "My Form" is a form created by us and "Hello Item" is a item that is appended in this form using append method.

Syntax of J2ME Form Class File name AppendItem.java

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

public class AppendItem extends MIDlet{
  private Display display;
  private MIDlet midlet;

  public void startApp(){
  Form form = new MyForm("MY FORM");
  display = Display.getDisplay(this);
  display.setCurrent(form);
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){}

  class MyForm extends Form implements CommandListener{
  private StringItem textItem;
  private Command exit;
  
  public MyForm(String title){
  super(title);
  exit = new Command("Exit", Command.BACK, 1);
  this.textItem = new StringItem (null, "Hello Item");
  addCommand(exit);
  append(this.textItem);
  this.setCommandListener(this);
  }

  public void commandAction(Command c, Displayable d){
  String label = c.getLabel();
  if(label.equals("Exit")){
  midlet.notifyDestroyed()
  }
  }
  }
}

Download Source Code

Related Tags for J2ME Form Class:
cimageclassimagesormtextj2meformgeneralusergettypescreenusersvaluefieldfieldsappendthisaiappshowtexforieexamplevaluestoexamextendldshexteitextendsitemitemscanusepeimfirstinrmextendingasmntoutcaletjclesememsendallagepenmehowppxaxampssueediscanyisirllmplgodiscussandarxtvascrssthshostabapaluendingendsendsldsmagepleplndono


More Tutorials from this section

Ask Questions?    Discuss: J2ME Form Class   View All Comments

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.