// Writing text directly on display without a label import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class StringText extends MIDlet implements CommandListener { private Display display; // a display private Form fmMain; // form private Command cmExit; // exit command private Command cmNext; // next command private int msgIndex; // index of message on the form private int count = 0; // a counter to count the number times in a loop public StringText(){ // constructor display = Display.getDisplay(this); // create commands cmExit = new Command("Exit", Command.EXIT, 1); cmNext = new Command("Next", Command.SCREEN, 1); // Create form, add command and listen for events fmMain = new Form("Preferences"); // form title fmMain.addCommand(cmExit); fmMain.addCommand(cmNext); // add message and save the message index msgIndex = fmMain.append("Userid: JohnSmith"); // listen for event fmMain.setCommandListener(this); } // start App public void startApp(){ display.setCurrent(fmMain); } // pause app public void pauseApp(){ } // Destroy app public void destroyApp(boolean unconditional){ } public void commandAction(Command c, Displayable s){ if(c == cmNext){ // check if the chosen command is Next if( count++ == 0){ // and check if loop counter is 0 /* ----------------------------------------------- option 1 This is the first Time through this method ... -------------------------------------------*/ StringItem tmpItem = (StringItem) fmMain.get(msgIndex); System.out.println("tmpItem.getText(): " + tmpItem.getLabel()); System.out.println("tmpItem.getText(): " + tmpItem.getText()); // inherited from item class tmpItem.setLabel("Account #: "); tmpItem.setText("222"); } else { /* Option 2 Second time through this method ... ----------------------------------------*/ fmMain.set(msgIndex, new StringItem("passWord: ", "letmein")); // Remove the Next command fmMain.removeCommand(cmNext); } } else if (c == cmExit){ destroyApp(false); notifyDestroyed(); } } }