简体   繁体   中英

Custom text input field in J2ME

I'm currently extending from CustomItem and creating my own TextField , is there any way that I can type in it and be able to retrieve that later?

The code I have right now is very basic, just a class extending from CustomItem , here's the code :

public class AlaaTextField extends CustomItem{

    public AlaaTextField(String label) {
        super(label);
        this.setPreferredSize(240, 20);  
    }

    protected int getMinContentHeight() {
        return 20;
    }

    protected int getMinContentWidth() {
        return 240;
    }

    protected int getPrefContentHeight(int width) {
        return 20;
    }

    protected int getPrefContentWidth(int height) {
        return 240;
    }

    protected void paint(Graphics g, int w, int h) {  
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, w, h);  
    }  
}

http://pastebin.com/RM5eY3q8

Yes you can do it, theoretically.

But it is a lot of work, as you need to write all the code to handle keystrokes, and write your own virtual keyboard.

An alternative is to use a library from somebody who has done all the work for you. For example I know it is possible with LWUIT Library. But these libraries are also quite complex to use, and Java-ME is a shrinking platform. So I don't think I can recommend it today.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM