3 Replies - 2652 Views - Last Post: 01 February 2011 - 05:26 PM

#1 SHENGTON  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

How to Search, Compare, and Replace text in the TextBox in J2ME?

Posted 20 January 2011 - 09:16 AM

Hello, good evening.

I'm having a hard time with this on how to search and compare the String array to the TextBox, and replace the text in the textbox.

Here's my code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Command;

public class TextBoxMIDlet extends MIDlet implements CommandListener
{
  private Display display;
  private static String[] realWord = {"text","speak","laugh out loud","no problem","be right back"};
  private static String[] txtWord = {"txt","spk","lol","np","brb"};
  private Command txtspk = new Command("Correct Textspeak", Command.ITEM, 0);
  private Command exit = new Command("Exit", Command.EXIT, 0);
  private TextBox message;

  public TextBoxMIDlet() {
    display = Display.getDisplay(this);
  }

  public void startApp() {
      message = new TextBox ("TextBox Example", null, 256, TextField.ANY);
      message.addCommand(txtspk);
      message.addCommand(exit);
      message.setCommandListener(this);
      display.setCurrent(message);
  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional){}

  public void commandAction(Command command, Displayable displayable)
  {
      if (command == exit)
      {
          destroyApp(true);
          notifyDestroyed();
      }
      if (command == txtspk)
      {
          for(int a = 0; a < realWord.length; a++)
          {
              if(message.getString().equalsIgnoreCase(realWord[a]))
              {
                  message = message.setString(realWord[a]);
              }
          }
          display.setCurrent(message);
      }
  }
}



I'm having a problem with this this part:
      if (command == txtspk)
      {
          for(int a = 0; a < txtWord.lenght; a++)
          {
              if(message.getString().equalsIgnoreCase(txtWord[a]))
              {
                  message = message.setString(realWord[a]);
              }
          }
          display.setCurrent(message);
      }


I don't know how to figure it out. What's the exact syntax should I put there?

Hope someone will help me with this.

Thanks advance.

Is This A Good Question/Topic? 0
  • +

Replies To: How to Search, Compare, and Replace text in the TextBox in J2ME?

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1011
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: How to Search, Compare, and Replace text in the TextBox in J2ME?

Posted 20 January 2011 - 08:24 PM

this code:
message = message.setString(realWord[a]); 

the setString method of TextBox is declared as void, why do you try to use it's return value? there is no one..
use:
message.setString(realWord[a]); 

Was This Post Helpful? 0
  • +
  • -

#3 SHENGTON  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

Re: How to Search, Compare, and Replace text in the TextBox in J2ME?

Posted 23 January 2011 - 07:24 PM

Hello japanir, good morning. :)

I'm still a newbie with this, sory with my codes.

What code should I suppose to put there in that line?
Was This Post Helpful? 0
  • +
  • -

#4 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1011
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: How to Search, Compare, and Replace text in the TextBox in J2ME?

Posted 01 February 2011 - 05:26 PM

The line:
message = message.setString(realWord[a]);

should be simply:
message.setString(realWord[a]);

so the updated code should look like:
if (command == txtspk)
{
    for(int a = 0; a < txtWord.lenght; a++)
    {
        if(message.getString().equalsIgnoreCase(txtWord[a]))
        {
            message.setString(realWord[a]);
        }
    }
    display.setCurrent(message);
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1