2

以下のコードに問題がありますが、これfrmChinese.append(txtField);は機能しません。

このテキストフィールドをフォームにバインドする正しい方法は何ですか?私が使用したヘッダーファイルとライブラリも言及されています。

package com.lbs;

import com.lbs.MidletSplashScreen;
import com.sun.lwuit.*;
import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;

import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import java.io.IOException;

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

public class Chinese extends Form implements ActionListener {
    Form frmChinese = null;
    Command cmdExit = null;
    TextField txtField = null;

    Chinese() {
        frmChinese = this;
        frmChinese.setTitle("Chinese");
        frmChinese.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        this.getStyle().setBgColor(0xFF5240);
        ShowUi();
        cmdExit = new Command("Exit");
        Command cmdBack = new Command("Back"); // new command with name Back
        frmChinese.addCommand(cmdExit);// add command in Form

        frmChinese.addCommand(cmdBack);// add command in Form
        frmChinese.setBackCommand(cmdBack); // setting back command 
        frmChinese.addCommandListener(this);  // register action listener in form

    }

    private void ShowUi() {
        txtField = new TextField("","Search", 20, TextField.ANY);
        frmChinese.append(txtField); 
    }
4

1 に答える 1

1

使用する必要があるのは、フォームクラスのaddComponentメソッドです。lwuitでは、基本的なインターフェイス要素はコンポーネントです。このコンポーネントをフォームのレイアウトに追加すると、いくつかのクールなデザインを作成できます。

ここを見てください:

LWUITレイアウト

于 2012-12-26T16:00:11.850 に答える