📄 textbox.java
字号:
/** * Deletes characters from the <code>TextBox</code>. * * <p>The <code>offset</code> and <code>length</code> parameters must * specify a valid range of characters within * the contents of the <code>TextBox</code>. * The <code>offset</code> parameter must be within the * range <code>[0..(size())]</code>, inclusive. * The <code>length</code> parameter * must be a non-negative integer such that * <code>(offset + length) <= size()</code>.</p> * * @param offset the beginning of the region to be deleted * @param length the number of characters to be deleted * * @throws IllegalArgumentException if the resulting contents * would be illegal for the current * <a href="TextField.html#constraints">input constraints</a> * @throws StringIndexOutOfBoundsException if <code>offset</code> * and <code>length</code> do not * specify a valid range within the contents of the <code>TextBox</code> */ public void delete(int offset, int length) { textField.delete(offset, length); } /** * Returns the maximum size (number of characters) that can be * stored in this <code>TextBox</code>. * @return the maximum size in characters * @see #setMaxSize */ public int getMaxSize() { return textField.getMaxSize(); } /** * Sets the maximum size (number of characters) that can be * contained in this * <code>TextBox</code>. If the current contents of the * <code>TextBox</code> are larger than * <code>maxSize</code>, the contents are truncated to fit. * * @param maxSize the new maximum size * * @return assigned maximum capacity - may be smaller than requested. * @throws IllegalArgumentException if <code>maxSize</code> is zero or less. * @throws IllegalArgumentException if the contents * after truncation would be illegal for the current * <a href="TextField.html#constraints">input constraints</a> * @see #getMaxSize */ public int setMaxSize(int maxSize) { return textField.setMaxSize(maxSize); } /** * Gets the number of characters that are currently stored in this * <code>TextBox</code>. * @return the number of characters */ public int size() { // returns a value relative to the display text including formatting return textField.size(); } /** * Gets the current input position. For some UIs this may block and ask * the user for the intended caret position, and on other UIs this may * simply return the current caret position. * * @return the current caret position, <code>0</code> if at the beginning */ public int getCaretPosition() { // returns a value relative to the flat input text return textField.getCaretPosition(); } /** * Sets the input constraints of the <code>TextBox</code>. If the * current contents * of the <code>TextBox</code> do not match the new constraints, * the contents are * set to empty. * * @param constraints see * <a href="TextField.html#constraints">input constraints</a> * * @throws IllegalArgumentException if the value of the constraints * parameter is invalid * @see #getConstraints */ public void setConstraints(int constraints) { textField.setConstraints(constraints); } /** * Gets the current input constraints of the <code>TextBox</code>. * * @return the current constraints value (see * <a href="TextField.html#constraints">input constraints</a>) * @see #setConstraints */ public int getConstraints() { return textField.getConstraints(); } /** * Sets a hint to the implementation as to the input mode that should be * used when the user initiates editing of this * <code>TextBox</code>. The * <code>characterSubset</code> parameter names a subset of Unicode * characters that is used by the implementation to choose an initial * input mode. If <code>null</code> is passed, the implementation should * choose a default input mode. * * <p>See <a href="TextField#modes">Input Modes</a> for a full * explanation of input modes. </p> * * @param characterSubset a string naming a Unicode character subset, * or <code>null</code> * * @since MIDP 2.0 */ public void setInitialInputMode(String characterSubset) { textField.setInitialInputMode(characterSubset); } /** * Sets the title of the <code>Displayable</code>. If * <code>null</code> is given, * removes the title. * * <P>If the <code>Displayable</code> is actually visible on * the display, * the implementation should update * the display as soon as it is feasible to do so.</P> * * <P>The existence of a title may affect the size * of the area available for <code>Displayable</code> content. * If the application adds, removes, or sets the title text at runtime, * this can dynamically change the size of the content area. * This is most important to be aware of when using the * <code>Canvas</code> class.</p> * * @param s the new title, or <code>null</code> for no title * @since MIDP 2.0 * @see #getTitle */ public void setTitle(String s) { super.setTitle(s); // We override this method from Displayable to set the title // on our internal Form which is doing all our rendering form.setTitle(s); } /** * Sets a ticker for use with this <code>Displayable</code>, * replacing any * previous ticker. * If <code>null</code>, removes the ticker object * from this <code>Displayable</code>. The same ticker may be shared by * several <code>Displayable</code> * objects within an application. This is done by calling * <code>setTicker()</code> * with the same <code>Ticker</code> object on several * different <code>Displayable</code> objects. * If the <code>Displayable</code> is actually visible on the display, * the implementation should update * the display as soon as it is feasible to do so. * * <p>The existence of a ticker may affect the size * of the area available for <code>Displayable's</code> contents. * If the application adds, removes, or sets the ticker text at runtime, * this can dynamically change the size of the content area. * This is most important to be aware of when using the * <code>Canvas</code> class. * * @param ticker the ticker object used on this screen * @since MIDP 2.0 * @see #getTicker */ public void setTicker(Ticker ticker) { super.setTicker(ticker); // We override this method from Displayable to set the ticker // on our internal Form which is doing all our rendering form.setTicker(ticker); } /* * package private */ /** * Called to commit any pending user interaction for the textfield. * Override the no-op in Displayable. */ void commitPendingInteraction() { textField.commitPendingInteraction(); } /** * Notify this Displayable it is being shown on the given Display * * @param d the Display showing this Displayable */ void callShowNotify(Display d) { super.callShowNotify(d); form.callShowNotify(d); } /** * Notify this Displayable it is being hidden on the given Display * * @param d the Display hiding this Displayable */ void callHideNotify(Display d) { super.callHideNotify(d); form.callHideNotify(d); } /** * Called by the event thread to invalidate the contents * of this TextBox * * @param src the Item which may have caused the invalidation */ void callInvalidate(Item src) { form.callInvalidate(src); } /** * Called by the event thread to notify an ItemStateChangeListener * that an item has changed * * @param src the Item which has changed */ void callItemStateChanged(Item src) { form.callItemStateChanged(src); } /** * Handle a key pressed event * * @param keyCode The key that was pressed */ void callKeyPressed(int keyCode) { form.callKeyPressed(keyCode); } /** * Handle a key released event * * @param keyCode The key that was pressed */ void callKeyReleased(int keyCode) { form.callKeyReleased(keyCode); } /** * Handle a key repeated event * * @param keyCode The key that was keyRepeated */ void callKeyRepeated(int keyCode) { form.callKeyRepeated(keyCode); } /** * Handle a key typed event * * @param keyCode The key that was pressed */ void callKeyTyped(char keyCode) { form.callKeyTyped(keyCode); } /** * Paint the content of this TextBox * * @param g The Graphics object to paint to * @param target the target Object of this repaint */ void callPaint(Graphics g, Object target) { super.callPaint(g, target); form.callPaint(g, target); }} // class TextBox
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -