开发者

How to create ComboBox in J2ME?

开发者 https://www.devze.com 2023-03-17 16:12 出处:网络
I want to create a function which takes two arguments A String value (name) An array of String objects The function creates LWUIT Combobox with these two parameters and returns a ComboBox varialbl

I want to create a function which takes two arguments

  1. A String value (name)
  2. An array of String objects

The function creates LWUIT Combobox with these two parameters and returns a ComboBox varialble...

I have written following code ...

 public void createComboxBox(String recStoreName,String []开发者_Python百科 values){
    comboBox = new ComboBox(recStoreName, values);
    surveyForm.addComponent(comboBox);

}


   //create a form and set its title
    Form f = new Form("Simple ComboBox");

    //set layout manager for the form
    //f.setLayout(new FlowLayout());

    //set form background colour
    f.getStyle().setBgColor(0xd5fff9);
    .
    .
    .

The first two lines of code are quite self-explanatory and should be familiar to AWT/Swing developers. The third line sets the background color attribute for the form.

The combo box is also instantiated in a similar manner:

    // Create a set of items
    String[] items = { "Red", "Blue", "Green", "Yellow" };

    //create a combobox with String[] items
    ComboBox combobox = new ComboBox(items);

Resource

  • Using Styles, Themes, and Painters with LWUIT

Also See

  • The Lightweight User Interface Toolkit (LWUIT): An Introduction


Just create the bean class like set the key and value. For example,

public void beanClass {

String value;
String key;

 public beanClass() {
} 
public void setValue(String value) {
this.value = value;
public void getValue() {
return value;
}
public void setValue(String key) {
this.key= key;
public void getKey() {
return key;
}
}

then create the beanClass array on your class and pass the Key's and Value's. then pass the beanClass array to ComboBox.

comboBox.getSelectedItem() returns the beanClass. So you can get the key and value from selected beanClass.

0

精彩评论

暂无评论...
验证码 换一张
取 消