textfield.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,236 行 · 第 1/4 页

JAVA
1,236
字号
 */public class TextField extends Item {    /**     * The user is allowed to enter any text.     * <A HREF="Form.html#linebreak">Line breaks</A> may be entered.     *     * <P>Constant <code>0</code> is assigned to <code>ANY</code>.</P>     */    public final static int ANY = 0;    /**     * The user is allowed to enter an e-mail address.     *     * <P>Constant <code>1</code> is assigned to <code>EMAILADDR</code>.</P>     */    public final static int EMAILADDR = 1;    /**     * The user is allowed to enter only an integer value. The implementation     * must restrict the contents either to be empty or to consist of an     * optional minus sign followed by a string of one or more decimal     * numerals.  Unless the value is empty, it will be successfully parsable     * using {@link java.lang.Integer#parseInt(String)}.     *     * <P>The minus sign consumes space in the text object.  It is thus     * impossible to enter negative numbers into a text object whose maximum     * size is <code>1</code>.</P>     *     * <P>Constant <code>2</code> is assigned to <code>NUMERIC</code>.</P>     */    public final static int NUMERIC = 2;    /**     * The user is allowed to enter a phone number. The phone number is a     * special     * case, since a phone-based implementation may be linked to the     * native phone     * dialing application. The implementation may automatically start a phone     * dialer application that is initialized so that pressing a single key     * would be enough to make a call. The call must not made automatically     * without requiring user's confirmation.  Implementations may also     * provide a feature to look up the phone number in the device's phone or     * address database.     *     * <P>The exact set of characters allowed is specific to the device and to     * the device's network and may include non-numeric characters, such as a     * &quot;+&quot; prefix character.</P>     *     * <P>Some platforms may provide the capability to initiate voice calls     * using the {@link javax.microedition.midlet.MIDlet#platformRequest     * MIDlet.platformRequest} method.</P>     *     * <P>Constant <code>3</code> is assigned to <code>PHONENUMBER</code>.</P>     */    public final static int PHONENUMBER = 3;    /**     * The user is allowed to enter a URL.     *     * <P>Constant <code>4</code> is assigned to <code>URL</code>.</P>     */    public final static int URL = 4;    /**     * The user is allowed to enter numeric values with optional decimal     * fractions, for example &quot;-123&quot;, &quot;0.123&quot;, or     * &quot;.5&quot;.     *     * <p>The implementation may display a period &quot;.&quot; or a     * comma &quot;,&quot; for the decimal fraction separator, depending on     * the conventions in use on the device.  Similarly, the implementation     * may display other device-specific characters as part of a decimal     * string, such as spaces or commas for digit separators.  However, the     * only characters allowed in the actual contents of the text object are     * period &quot;.&quot;, minus sign &quot;-&quot;, and the decimal     * digits.</p>     *     * <p>The actual contents of a <code>DECIMAL</code> text object may be     * empty.  If the actual contents are not empty, they must conform to a     * subset of the syntax for a <code>FloatingPointLiteral</code> as defined     * by the <em>Java Language Specification</em>, section 3.10.2.  This     * subset syntax is defined as follows: the actual contents     * must consist of an optional minus sign     * &quot;-&quot;, followed by one or more whole-number decimal digits,     * followed by an optional fraction separator, followed by zero or more     * decimal fraction digits.  The whole-number decimal digits may be     * omitted if the fraction separator and one or more decimal fraction     * digits are present.</p>     *     * <p>The syntax defined above is also enforced whenever the application     * attempts to set or modify the contents of the text object by calling     * a constructor or a method.</p>     *     * <p>Parsing this string value into a numeric value suitable for     * computation is the responsibility of the application.  If the contents     * are not empty, the result can be parsed successfully by     * <code>Double.valueOf</code> and related methods if they are present     * in the runtime environment. </p>     *     * <p>The sign and the fraction separator consume space in the text     * object.  Applications should account for this when assigning a maximum     * size for the text object.</p>     *     * <P>Constant <code>5</code> is assigned to <code>DECIMAL</code>.</P>     *     */    public static final int DECIMAL = 5;    /**     * Indicates that the text entered is confidential data that should be     * obscured whenever possible.  The contents may be visible while the     * user is entering data.  However, the contents must never be divulged     * to the user.  In particular, the existing contents must not be shown     * when the user edits the contents.  The means by which the contents     * are obscured is implementation-dependent.  For example, each     * character of the data might be masked with a     * &quot;<code>*</code>&quot; character.  The     * <code>PASSWORD</code> modifier is useful for entering     * confidential information     * such as passwords or personal identification numbers (PINs).     *     * <p>Data entered into a <code>PASSWORD</code> field is treated     * similarly to <code>SENSITIVE</code>     * in that the implementation must never store the contents into a     * dictionary or table for use in predictive, auto-completing, or other     * accelerated input schemes.  If the <code>PASSWORD</code> bit is     * set in a constraint     * value, the <code>SENSITIVE</code> and     * <code>NON_PREDICTIVE</code> bits are also considered to be     * set, regardless of their actual values.  In addition, the     * <code>INITIAL_CAPS_WORD</code> and     * <code>INITIAL_CAPS_SENTENCE</code> flag bits should be ignored     * even if they are set.</p>     *     * <p>The <code>PASSWORD</code> modifier can be combined with     * other input constraints     * by using the bit-wise <code>OR</code> operator (<code>|</code>).     * The <code>PASSWORD</code> modifier is not     * useful with some constraint values such as     * <code>EMAILADDR</code>, <code>PHONENUMBER</code>,     * and <code>URL</code>. These combinations are legal, however,     * and no exception is     * thrown if such a constraint is specified.</p>     *     * <p>Constant <code>0x10000</code> is assigned to     * <code>PASSWORD</code>.</p>     */    public static final int PASSWORD = 0x10000;    /**     * Indicates that editing is currently disallowed.  When this flag is set,     * the implementation must prevent the user from changing the text     * contents of this object.  The implementation should also provide a     * visual indication that the object's text cannot be edited.  The intent     * of this flag is that this text object has the potential to be edited,     * and that there are circumstances where the application will clear this     * flag and allow the user to edit the contents.     *     * <p>The <code>UNEDITABLE</code> modifier can be combined with     * other input constraints     * by using the bit-wise <code>OR</code> operator (<code>|</code>).     *     * <p>Constant <code>0x20000</code> is assigned to <code>UNEDITABLE</code>.     *     */    public static final int UNEDITABLE = 0x20000;    /**     * Indicates that the text entered is sensitive data that the     * implementation must never store into a dictionary or table for use in     * predictive, auto-completing, or other accelerated input schemes.  A     * credit card number is an example of sensitive data.     *     * <p>The <code>SENSITIVE</code> modifier can be combined with other input     * constraints by using the bit-wise <code>OR</code> operator     * (<code>|</code>).</p>     *     * <p>Constant <code>0x40000</code> is assigned to     * <code>SENSITIVE</code>.</p>     *     */    public static final int SENSITIVE = 0x40000;    /**     * Indicates that the text entered does not consist of words that are     * likely to be found in dictionaries typically used by predictive input     * schemes.  If this bit is clear, the implementation is allowed to (but     * is not required to) use predictive input facilities.  If this bit is     * set, the implementation should not use any predictive input facilities,     * but it instead should allow character-by-character text entry.     *     * <p>The <code>NON_PREDICTIVE</code> modifier can be combined     * with other input     * constraints by using the bit-wise <code>OR</code> operator     * (<code>|</code>).     *     * <P>Constant <code>0x80000</code> is assigned to     * <code>NON_PREDICTIVE</code>.</P>     *     */    public static final int NON_PREDICTIVE = 0x80000;    /**     * This flag is a hint to the implementation that during text editing, the     * initial letter of each word should be capitalized.  This hint should be     * honored only on devices for which automatic capitalization is     * appropriate and when the character set of the text being edited has the     * notion of upper case and lower case letters.  The definition of     * word boundaries is implementation-specific.     *     * <p>If the application specifies both the     * <code>INITIAL_CAPS_WORD</code> and the     * <code>INITIAL_CAPS_SENTENCE</code> flags,     * <code>INITIAL_CAPS_WORD</code> behavior should be used.     *     * <p>The <code>INITIAL_CAPS_WORD</code> modifier can be combined     * with other input     * constraints by using the bit-wise <code>OR</code> operator     * (<code>|</code>).     *     * <p>Constant <code>0x100000</code> is assigned to     * <code>INITIAL_CAPS_WORD</code>.     *     */    public static final int INITIAL_CAPS_WORD = 0x100000;    /**     * This flag is a hint to the implementation that during text editing, the     * initial letter of each sentence should be capitalized.  This hint     * should be honored only on devices for which automatic capitalization is     * appropriate and when the character set of the text being edited has the     * notion of upper case and lower case letters.  The definition of     * sentence boundaries is implementation-specific.     *     * <p>If the application specifies both the     * <code>INITIAL_CAPS_WORD</code> and the     * <code>INITIAL_CAPS_SENTENCE</code> flags,     * <code>INITIAL_CAPS_WORD</code> behavior should be used.     *     * <p>The <code>INITIAL_CAPS_SENTENCE</code> modifier can be     * combined with other input     * constraints by using the bit-wise <code>OR</code> operator     * (<code>|</code>).     *     * <p>Constant <code>0x200000</code> is assigned to     * <code>INITIAL_CAPS_SENTENCE</code>.     *     */    public static final int INITIAL_CAPS_SENTENCE = 0x200000;    /**     * The mask value for determining the constraint mode. The application     * should     * use the bit-wise <code>AND</code> operation with a value returned by     * <code>getConstraints()</code> and     * <code>CONSTRAINT_MASK</code> in order to retrieve the current     * constraint mode,     * in order to remove any modifier flags such as the     * <code>PASSWORD</code> flag.     *     * <P>Constant <code>0xFFFF</code> is assigned to     * <code>CONSTRAINT_MASK</code>.</P>     */    public final static int CONSTRAINT_MASK = 0xFFFF;    /**     * Creates a new <code>TextField</code> object with the given label, initial     * contents, maximum size in characters, and constraints.     * If the text parameter is <code>null</code>, the     * <code>TextField</code> is created empty.     * The <code>maxSize</code> parameter must be greater than zero.     * An <code>IllegalArgumentException</code> is thrown if the     * length of the initial contents string exceeds <code>maxSize</code>.     * However,     * the implementation may assign a maximum size smaller than the      * application had requested.  If this occurs, and if the length of the      * contents exceeds the newly assigned maximum size, the contents are      * truncated from the end in order to fit, and no exception is thrown.     *     * @param label item label     * @param text the initial contents, or <code>null</code> if the     * <code>TextField</code> is to be empty     * @param maxSize the maximum capacity in characters     * @param constraints see <a href="#constraints">input constraints</a>     *     * @throws IllegalArgumentException if <code>maxSize</code> is zero or less     * @throws IllegalArgumentException if the value of the constraints     * parameter     * is invalid     * @throws IllegalArgumentException if <code>text</code> is illegal     * for the specified constraints     * @throws IllegalArgumentException if the length of the string exceeds     * the requested maximum capacity      */    public TextField(String label, String text, int maxSize,                      int constraints) {        super(label);        synchronized (Display.LCDUILock) {            // IllegalArgumentException thrown here            buffer = new DynamicCharacterArray(maxSize); 	    // Constraint value is checked here. Since textFieldLF is not	    // yet created, no LF notification will happen.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?