package textboxexample; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class TextBoxExample extends MIDlet implements CommandListener { private TextBox textbox; private Display display; private static final int screenLength = 100; //commands private static final Command STOP = new Command("Stop", Command.EXIT,0); private static final Command CLEAR = new Command("Clear Screen", Command.SCREEN,1); private static final Command GO = new Command("GO",Command.SCREEN,1); public TextBoxExample() { } public void startApp() { textbox = new TextBox("TextBoxExample", "Delete this text and enter your own, then select option GO from the menu",screenLength,TextField.ANY); //add commands textbox.addCommand(STOP); textbox.addCommand(CLEAR); textbox.addCommand(GO); textbox.setCommandListener(this); //display the screen display = Display.getDisplay(this); display.setCurrent(textbox); } public void pauseApp() { } public void destroyApp(boolean b) { } //command Actions public void commandAction(Command c, Displayable d) { if (c == GO) { String text = textbox.getString(); //create the Ticker Ticker ticker = new Ticker(text); textbox.setTicker(ticker); } if (c == STOP) { destroyApp(true); notifyDestroyed(); } if (c == CLEAR) { textbox.setString(null); } } }