0

嗨,我输入了一个代码,但它似乎不起作用,你能告诉我错误是什么吗?

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

    }


}

键入的内容在屏幕上不可见 我刚刚创建了一个在其中扩展 VerticalFieldManager 的 CustomTextField 我添加了一个 EditField ,它被添加到 VerticalFieldManager

但它不起作用我的意思是它不显示我在屏幕上输入的内容是什么错误你能检查一下吗

我确实使用调用 CustomTextField

CustomTextField ctf=new CustomTextField(100,200):
4

1 回答 1

1

查看

protected void paint(Graphics graphics) 

添加

super.paint(g);

最后在里面。

于 2012-05-16T12:12:11.337 回答