J2ME Text Box Example

This application illustrates how to create the text box using TextBox class. The
TextBox class is a Screen that allows the user to enter and edit text. A TextBox
has a maximum size, which is the maximum number of characters that can be stored
in the object at any time. The following are the methods used in class:
- delete(int offset, int length)
- getCaretPosition()
- getChars(char[] data)
- getConstraints()
- getMaxSize()
- getString()
- insert(char[] data, int offset, int length, int position)
- insert(String src, int position)
- setChars(char[] data, int offset, int length)
- setConstraints(int constraints)
- setMaxSize(int maxSize)
- setString(String text)
- size()
These methods are accessible in your MIDlet. The application is as follows:

TextBoxMIDlet.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TextBoxMIDlet extends MIDlet{
private Display display;
public TextBoxMIDlet() {
display = Display.getDisplay(this);
}
public void startApp() {
TextBox t = new TextBox("TextBox Example",
"Hello Sandeep Kumar Suman !", 256, 0);
display.setCurrent(t);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}
|
Download Source Code

|