Results 1 to 5 of 5
  1. #1
    SHENGTON is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

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

    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:
    Java 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[] txtWord = {"txt","spk","lol","np","brb"};
      private static String[] realWord = {"text","speak","laugh out loud","no problem","be right back"};
      private Command txtspk = new Command("Correct Textspeak", Command.ITEM, 0);
      private Command exit = new Command("Exit", Command.EXIT, 0);
      private TextBox t;
    
      public TextBoxMIDlet() {
        display = Display.getDisplay(this);
      }
    
      public void startApp() {
          t = new TextBox ("TextBox Example", null, 256, TextField.ANY);
          t.addCommand(txtspk);
          t.addCommand(exit);
          t.setCommandListener(this);
          display.setCurrent(t);
      }
    
      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 < txtWord.length; a++)
              {
                  if(t.getString().equalsIgnoreCase(realWord[a]))
                  {
                      t = t.getString().substring(realWord[a]);
                  }
              }
              System.out.println(t);
          }
      }
    }
    I'm having a problem with this this part:
    Java Code:
          if (command == txtspk)
          {
              for(int a = 0; a < txtWord.length; a++)
              {
                  if(t.getString().equalsIgnoreCase(realWord[a]))
                  {
                      t = t.getString().substring(realWord[a]);
                  }
              }
              System.out.println(t);
          }
    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.

  2. #2
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Im not too familiar with java mobile stuff, but ill try to help anyway.

    Instead of saying "t = something", try "t.set(something)" - im presuming its "setString" but i dont know for deffo.

    also its just a guess but i have a feeling your if statement should be testing if it equals txtWord[a] not realWord[a]

    Hope this helps!

  3. #3
    SHENGTON is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Hello berkeleybross, good morning. :)

    Ooppss sorry, I forgot to erase the "txtWord" string array. Thanks for correcting me for that berkeleybross.

    Here's the new code:
    Java 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 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]);
                  }
              }
              System.out.println(message);
          }
      }
    }

  4. #4
    SHENGTON is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Anyone?...............

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,843
    Rep Power
    8

Similar Threads

  1. Copying a text value from a textbox to a label
    By Weeman5872 in forum New To Java
    Replies: 3
    Last Post: 01-16-2011, 02:32 PM
  2. Regex search and replace
    By joe robles in forum Advanced Java
    Replies: 1
    Last Post: 09-25-2010, 02:32 PM
  3. Replies: 5
    Last Post: 09-14-2010, 04:03 PM
  4. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 04:04 PM
  5. Replies: 2
    Last Post: 08-18-2008, 02:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •