我在下面的代码中遇到问题,这个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);
}
答案 0 :(得分:1)
您需要使用的是来自Form Class的te addComponent方法。在lwuit中,基本的界面元素是组件。将此组件添加到表单的布局中,您可以构建一些很酷的设计。
看看这里: