How to use pop-up TextBox in J

来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 03:41 点击:
Overview
One of the Displayables in LCDUI is TextBox (extending Screen class), which allows user to enter and edit text. It is commonly used for entering relatively short texts, even single words. In any case TextBox has used the whole screen, which has made user experience bad. Now in S60 5th Edition new mode of pop-up TextBox is introduced. By using a JAD attribute "Nokia-UI-Enhancement" with value "PopUpTextBox" all the TextBox screens are shown as smaller dialogs, without obscuring the underlying screen.
Nokia-UI-Enhancement: PopUpTextBox
Pop-up TextBox does lack have some properties of "traditional" TextBox:
Ticker is not visible
Text input capacity indicator is not supported

An empty Pop-up TextBox has one line, but if needed, its size will grow. The exact maximum amount of visible lines depends on the screen size. In nHD screens (640x360 pixels) it is 5 rows of text. Inputting and editing text is possible by tapping on the TextBox.
The image below shows an empty pop-up TextBox on top of Canvas (in normal mode) and a pop-up TextBox with 5 rows of text
 
Here is a simple MIDlet demonstrating pop-up TextBox feature.
[edit]
Source code: PopUpTextBoxMIDlet.java
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
 
public class PopUpTextBoxMIDlet extends MIDlet {
    private PopUpTextBoxCanvas canvas;
    protected String canvasText = "Text from the TextBox";
 
    public void startApp() {
        canvas = new PopUpTextBoxCanvas(this);
        Display.getDisplay(this).setCurrent(canvas);
    }
 
    public void pauseApp() {
    }
 
    public void destroyApp(boolean unconditional) {
    }
 
    protected void closeTextBox(boolean update) {
        if (update) canvasText = canvas.textbox.getString();
        if (canvas.textbox != null) canvas.textbox = null;
        Display.getDisplay(this).setCurrent(canvas);
    }
 
    protected void showError(String title, String text) {
        Alert alert = new Alert(title, text, null, AlertType.ERROR);
        alert.setTimeout(Alert.FOREVER);
        alert.getType().playSound(Display.getDisplay(this));
        Displayable current = Display.getDisplay(this).getCurrent();
        if (current instanceof Alert) {}
        else Display.getDisplay(this).setCurrent(alert);
    }
}

[edit]
Source code: PopUpTextBox.java
import javax.microedition.lcdui.*;
 
public class PopUpTextBox extends TextBox implements CommandListener {
    private Command okCommand;
    private Command cancelCommand;
    private PopUpTextBoxMIDlet midlet;
   
    public PopUpTextBox(String title, String text, int maxsize, int constraints, PopUpTextBoxMIDlet midlet) {
        super(title, text, maxsize, constraints);
        this.midlet = midlet;
        okCommand = new Command("Ok", Command.OK, 1);
     
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Java编程语言的八大优点
    • JVM对象生命周期详细介绍
    • Java平台上的CRM系统
    • Java 算数测试小程序
    • Command(命令模式)
    • Java环境 使用Resin在NT环境下配置JSP环境
    • Java 一个简单的画图程序
    • Java 日历的小程序
    • Java 统计代码的小工具
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1