您好我输入了一段代码,但它似乎不起作用您是否会让我知道错误是什么?
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class CustomTextField extends VerticalFieldManager implements FocusChangeListener{
private int textWidth=0;
private Font font=Font.getDefault();
private int textHeight=0;
public EditField basicEditField;
public CustomTextField(int width,int height) {
textWidth=width;
textHeight=height;
VerticalFieldManager vfm=new VerticalFieldManager(Manager.FOCUSABLE);
basicEditField=new EditField(null,null,200, Field.EDITABLE|Field.FOCUSABLE|BasicEditField.NO_NEWLINE);
basicEditField.setFocusListener(this);
vfm.add(basicEditField);
add(vfm);
}
protected void sublayout(int maxWidth, int maxHeight) {
if(textWidth==0)
{
textWidth=maxWidth;
}
if(textHeight==0)
{
textHeight=maxHeight;
}
super.layout(textWidth, textHeight);
setExtent(textWidth, textHeight);
}
protected void paint(Graphics graphics) {
graphics.setColor(Color.BLACK);
graphics.drawRect(basicEditField.getLeft(),basicEditField.getTop(), textWidth, textHeight);
}
public void setHeight(int height) {
textHeight= height;
}
public void setWidth(int width) {
textWidth= width;
}
public Font getFont() {
return font;
}
public void setFont(Font font) {
this.font = font;
}
public void focusChanged(Field field, int eventType) {
if(eventType==FOCUS_GAINED)
{
if(field==basicEditField)
{
basicEditField.setCursorPosition(basicEditField.getText().length());
}
}
}
}
键入的内容无法在屏幕上显示 我刚刚创建了一个CustomTextField,它扩展了VerticalFieldManager 在里面 我添加了一个EditField,它将被添加到VerticalFieldManager
中但它确实无效 我的意思是它没有显示我在屏幕上键入的内容 你能看出来的错误是什么
我使用
调用CustomTextFieldCustomTextField ctf=new CustomTextField(100,200):
答案 0 :(得分:1)
检查
protected void paint(Graphics graphics)
添加
super.paint(g);
在它的最后。