Use of MIDP Advanced UI (iii) TextBox

Source: Internet
Author: User
Tags exit

When we need to move the data into the device, the textbox comes in handy, we use a total of four textbox constructor parameters, a textbox textbox = new TextBox (string title, string content, String maxLength, String Limittype, the first is the title, the second is the initial content of the textbox, the third is to allow the maximum length of the input characters, and the fourth is to restrict the inner type. It is worth noting that a textbox must append a command, otherwise the user will not be able to fire any behavior, and into this textbox.

The following is an example of a common textbox.

View Plainprint?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
Package Com.thinkrace.TextBox;
Import Javax.microedition.lcdui.Choice;
Import Javax.microedition.lcdui.ChoiceGroup;
Import Javax.microedition.lcdui.Command;
Import Javax.microedition.lcdui.CommandListener;
Import Javax.microedition.lcdui.Display;
Import javax.microedition.lcdui.Displayable;
Import Javax.microedition.lcdui.Form;
Import Javax.microedition.lcdui.TextBox;
Import Javax.microedition.lcdui.TextField;
Import Javax.microedition.lcdui.Ticker;
Import javax.microedition.midlet.*;
/**
* @author PENGJW
*/
public class Textboxdemo extends MIDlet implements commandlistener{
private display display;
private Choicegroup types;
Private Choicegroup options;
Private Form MainForm;
private static final Command cmd_exit = new Command ("EXIT", Command.exit, 1);
private static final Command cmd_back = new Command ("Back", Command.back, 1);
private static final Command cmd_show = new Command ("show", Command.screen, 1);
private static final string[] Textboxlabels ={
"Any Character", "Email", "number", "Decimal", "Phone", "URL"
};
private static final int[] Textboxtypes ={
Textfield.any, Textfield.emailaddr, Textfield.numeric,
Textfield.decimal, Textfield.phonenumber, Textfield.url
};
Firsttime is used to determine whether Textboxdemo is instantiated
Private Boolean firsttime;
Public Textboxdemo () {
/**
* Instructions from the document
* Display represents the manager of the display and input devices of the system.
* It includes methods for retrieving properties of the device and for requesting that objects is displayed on the device.
* There is exactly one instance of Display/MIDlet and the application can get
* A reference to "instance by calling" Getdisplay () method.
*/
display = Display.getdisplay (this);
Firsttime = true;
}
public void startApp () {
if (firsttime) {
MainForm = new Form ("Select a Text box Type");
Mainform.append ("Select a TextBox type");
types = new Choicegroup ("Choice Type", choice.exclusive, textboxlabels, NULL);
Mainform.append (types);
String[] Optionstrings = {"As Password", "Show Ticker"};
options = new Choicegroup ("Options", Choice.multiple, optionstrings, NULL);
Mainform.append (options);
Mainform.addcommand (Cmd_exit);
Mainform.addcommand (cmd_show);
Mainform.setcommandlistener (this);
Firsttime = false;
}
Set the currently displayed form
Display.setcurrent (MainForm);
}
public void Pauseapp () {
}
public void Destroyapp (Boolean unconditional) {
}
/**
* Abstract method to implement Commandlistener interface
* Do different things according to different command
*/
public void Commandaction (Command C, displayable D) {
if (c = = Cmd_exit) {
Destroyapp (FALSE);
Notifydestroyed ();
}
else if (c = = cmd_show) {
int Index = Types.getselectedindex ();
String title = Textboxlabels[index];
int choicetype = Textboxtypes[index];
Boolean[] flags = new BOOLEAN[2];
/**
* A description from the document that can be assigned to a BOOL array
* Query the state of a choicegroup and renturns to the state of all elements in the Boolean array.
*/
Options.getselectedflags (flags);
if (Flags[0]) {
Choicetype = Textfield.password;
}
TextBox textbox = new TextBox (title, "", 50,choicetype);
if (Flags[1]) {
Textbox.setticker (New Ticker ("TextBox:" + title));
}
Textbox.addcommand (Cmd_back);
Textbox.setcommandlistener (this);
Display.setcurrent (TextBox);
}
else if (c = = Cmd_back) {
Display.setcurrent (MainForm);
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.