Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

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

    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[] txtWord = {"txt","spk","lol","no prblm","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 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 < txtWord.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.length; a++)
              {
                  if(message.getString().equalsIgnoreCase(realWord[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.
    Last edited by SHENGTON; January 23rd, 2011 at 09:16 PM.


  2. #2
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

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

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

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

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

    This thread has been cross posted here:

    http://www.java-forums.org/cldc-midp/37514-how-search-compare-replace-text-textbox.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

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

    What exactly is the problem? Are any errors generated? What happens when you run the program?

    Where is the realWord array?!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

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

    Hello JavaPF,

    My problem is how do I compare the string in the textbox? What I mean is, I want to compare the substring to text in the Textbox. If the program found same with the txtWord, it replace the substring of realWord. For example, "tnx" will replace with "thanks" in the Textbox.

Similar Threads

  1. [SOLVED] 2DArry from Textbox input (pls hlp)
    By MoniD in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 1st, 2011, 08:17 PM
  2. [SOLVED] Replace Phrase in String
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: October 18th, 2010, 12:10 PM
  3. What can go wrong if you replace && with & in the following code:
    By scott01 in forum Java Theory & Questions
    Replies: 4
    Last Post: February 12th, 2010, 07:47 AM
  4. TextBox
    By tryingtoJava in forum AWT / Java Swing
    Replies: 3
    Last Post: October 7th, 2009, 10:05 AM
  5. make textbox in canvas
    By mahdi in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: October 6th, 2009, 07:10 AM