如何在J2ME中创建ComboBox?

发布于 2024-11-18 06:24:03 字数 337 浏览 5 评论 0原文

我想创建一个带有两个参数的函数

  1. 一个字符串值(名称)
  2. 一个字符串对象数组

该函数使用这两个参数创建 LWUIT Combobox 并返回一个 ComboBox 变量...

我编写了以下代码...

 public void createComboxBox(String recStoreName,String [] values){
    comboBox = new ComboBox(recStoreName, values);
    surveyForm.addComponent(comboBox);

}

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 [] values){
    comboBox = new ComboBox(recStoreName, values);
    surveyForm.addComponent(comboBox);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肩上的翅膀 2024-11-25 06:24:03
   //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);
    .
    .
    .

前两行代码非常不言自明,AWT/Swing 开发人员应该熟悉。第三行设置表单的背景颜色属性。

组合框也以类似的方式实例化:

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

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

资源


另请参阅

   //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


Also See

妞丶爷亲个 2024-11-25 06:24:03

只需创建 bean 类,就像设置键和值一样。
例如,

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;
}
}

然后在您的类上创建 beanClass 数组并传递键和值。然后将 beanClass 数组传递给 ComboBox

comboBox.getSelectedItem() 返回 beanClass。这样你就可以从选定的beanClass中获取键和值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文