Appending string in J2ME Form

In the previous example, you learned about how to add items in to the form. In this example we are going to add string into the form.

Appending string in J2ME Form

Appending string in J2ME Form

     

In the previous example, you learned about how to add items in to the form. In this example we are going to add string into the form. Both examples are almost same but the only difference is that this time we are using append string instead of append item.

Syntax for appending string into the form..

public int append(String str)

 

 

 

The Midlet will look like as follow..

Source Code of AppendString.java

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

public class AppendString extends MIDlet{
  private Display display;
  private AppendFormClass form;
  private MIDlet midlet;
  
  protected void startApp(){
  form = new AppendFormClass("Form Created"this);
  display = Display.getDisplay(this);
  display.setCurrent(form);
  }

  protected void pauseApp(){}

  protected void destroyApp(boolean unconditional){}

  class AppendFormClass extends Form implements CommandListener{
  private Command exit;
  private String string;
  
  public AppendFormClass(String title, MIDlet items){
  super(title);
  midlet = items;
  string = "Sandeep kumar suman";
  exit = new Command("Exit", Command.BACK, 1);
  append(string);
  this.addCommand(this.exit);
  this.setCommandListener(this);
  }

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

 

Download Source Code