Home J2me J2ME Form Class

Related Tutorials


 
 

Share on Google+Share on Google+

J2ME Form Class

Advertisement
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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 20, 2008

Related Tutorials

Discuss: J2ME Form Class   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Bobo
May 14, 2012
operating system phone

I'm happy
DMCA.com