Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home J2me Check Box Midlet Example

Related Tutorials


 
 

Share on Google+Share on Google+

Check Box Midlet Example

Advertisement
This example illustrates how to create check boxes in to your form. In this example we are creating a Form("Technologies") that is having four different choices, ChoiceGroup("JAVA", "J2ME", "J2EE", "JSF").

J2ME CheckBox ChoiceGroup MIDlet

     

This example illustrates how to create check boxes in to your form. In this example we are creating a Form("Technologies") that is having four different choices, ChoiceGroup("JAVA", "J2ME", "J2EE", "JSF"). if user select a check box and click on "Choose" button then the selected item will be display on the form. We are using StringItem to display the selected item on the form. We are creating a variable of array type ("message[ ]") and stored the size of selected item in it. Next we are creating a boolean type array ("get[ ]") to store the size of selected item then we have given a condition if get[] returns true then this will display the StringItem() with message and String value of selected item. The StringItem has only 2 methods that is:

  • getText()
  • setText(String text)

Constructor StringItem Syntax is:

  • StringItem(String label, String text) 

The Application look like as follows:

 

 

Source code of CheckBoxExample.java 

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


public class CheckBoxExample extends MIDlet implements CommandListener {
  private Display display;
  private Form form;
  private Command exit, choose;
  private ChoiceGroup technology;
  private int index;

  public CheckBoxExample() {
  form = new Form("Technologies");
  technology = new ChoiceGroup("Select Technology Which You Know", Choice.MULTIPLE);
  exit = new Command("Exit", Command.EXIT, 1);
  choose = new Command("Choose", Command.SCREEN, 2);  
  }

  public void startApp() {
  display = Display.getDisplay(this);
  technology.append("JAVA", null);
  technology.append("J2ME", null);
  technology.append("J2EE", null);
  technology.append("JSF", null); 

  index = form.append(technology);
  form.addCommand(exit);
  form.addCommand(choose);
  form.setCommandListener(this);
  display.setCurrent(form);
  }

  public void pauseApp(){}

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

  public void commandAction(Command c, Displayable displayable){
  String label = c.getLabel();
  if (label.equals("Choose")) {
  StringItem message[] = new StringItem[technology.size()];
  boolean get[] = new boolean[technology.size()];
  technology.getSelectedFlags(get);
  for (int i = 0; i < get.length; i++) {
  if (get[i]) {
  message[i] = new StringItem("Your Choice is: ", technology.getString(i));
  form.append(message[i]);
  }
  }
  form.delete(index);
  form.removeCommand(choose);
  } else if (label.equals("Exit")){
  destroyApp(false);
  }
  }
} 

 

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: October 3, 2008

Related Tutorials

Discuss: Check Box Midlet Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
sudhir kumar
April 17, 2012
using choice group in netbeans j2me

How the choice group using item name and item value.
DMCA.com