Results 1 to 5 of 5
  1. #1
    deeevo is offline Member
    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Default User Input for GUI error message

    I need help implementing the below code. It currently is the code for a search bar. User enters in keywords and then it displays the recipes matching in the interface. However, I want to implement an error message for invalid input. Currently with the below code it just brings up the error regardless, I added a break, but then it removed all the content from the interface. else if(recipe.foundWords(keys)) =! true) //do stuff ? is another option I tried.
    Obviously not the result I'm wanting.

    Java Code:
                for(CakeRecipe recipe : recipeSet.getAllCakeRecipes()) 
                {
                    if(recipe.foundWords(keys)) 
                    {
                        searchRecipe.add(recipe);
                    }
                    else
                    {
                        JOptionPane.showMessageDialog(this,"No recipe containing search words found.", "Error!",
                                                        JOptionPane.ERROR_MESSAGE);
                    }
                    
                }
    Suggestions?
    Last edited by deeevo; 05-24-2013 at 07:42 AM.

  2. #2
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: User Input for GUI error message

    if it's a string you can do this:

    Java Code:
    if(!recipe.foundWords(keys).equals(something in brackets here, the thing you want to compare recipe with)){
    JOptionPane.showMessageDialog(null, "Test" ,"Test", JOptionPane.ERROR_MESSAGE);
    }

  3. #3
    deeevo is offline Member
    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Default Re: User Input for GUI error message

    Quote Originally Posted by MR bruto View Post
    if it's a string you can do this:

    Java Code:
    if(!recipe.foundWords(keys).equals(something in brackets here, the thing you want to compare recipe with)){
    JOptionPane.showMessageDialog(null, "Test" ,"Test", JOptionPane.ERROR_MESSAGE);
    }
    if(recipe.foundWord(keys) ...etc returns a boolean. If entered words match words found, then it displays the recipes. Sorry I should of mentioned that in my first post.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,537
    Blog Entries
    7
    Rep Power
    20

    Default Re: User Input for GUI error message

    I something was found in the loop, don't display the error message; something like this:

    Java Code:
    boolean somethingFound= false;
    
    for(CakeRecipe recipe : recipeSet.getAllCakeRecipes())  {
        if(recipe.foundWords(keys)) {
            searchRecipe.add(recipe);
            somethingFound= true;
        }
    }
    
    if (!somethingFound) {
            JOptionPane.showMessageDialog(this,"No recipe containing search words found.", "Error!",
                                            JOptionPane.ERROR_MESSAGE);
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    deeevo is offline Member
    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    Default Re: User Input for GUI error message

    Quote Originally Posted by JosAH View Post
    I something was found in the loop, don't display the error message; something like this:

    Java Code:
    boolean somethingFound= false;
    
    for(CakeRecipe recipe : recipeSet.getAllCakeRecipes())  {
        if(recipe.foundWords(keys)) {
            searchRecipe.add(recipe);
            somethingFound= true;
        }
    }
    
    if (!somethingFound) {
            JOptionPane.showMessageDialog(this,"No recipe containing search words found.", "Error!",
                                            JOptionPane.ERROR_MESSAGE);
    }
    kind regards,

    Jos
    Cheers - appreciate it! It's working now however I was having trouble with the interface if invalid input was wrong, but I managed to fix that.

Similar Threads

  1. Replies: 2
    Last Post: 01-29-2013, 10:16 AM
  2. Replies: 1
    Last Post: 01-13-2013, 01:36 PM
  3. User input
    By the ole buc in forum New To Java
    Replies: 16
    Last Post: 12-11-2011, 07:08 PM
  4. Error Message when reading an input file.
    By Deluyxe in forum New To Java
    Replies: 8
    Last Post: 04-26-2009, 04:02 PM
  5. Built-in User Popup message boxes ?
    By BobZ in forum AWT / Swing
    Replies: 2
    Last Post: 02-06-2009, 06:23 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
  •