Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Check Box Midlet Example 
 

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[inew 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

                         

» View all related tutorials
Related Tags: c io vi lock this block set frame example ram exam locks e il manual blocks man in as m

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.