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 3 of 3

Thread: GUI user input error message

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    11
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default GUI user input 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 matches it against the recipe, returning true if so. It then 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.

                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?


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: GUI user input error message

    The snippet looks ok..
    Post a SSCCE

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    11
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: GUI user input error message

    Quote Originally Posted by jps View Post
    The snippet looks ok..
    Post a SSCCE
    The code runs and what not. However, right or a wrong keyword match still displays the error message. If wrong, it iterates 10 times (10 recipes in the array list) and then brings up a blank interface without showing any recipes. If it is right - the match, it iterates 10 times and then displays the correct recipe.

    I need to break from the iteration, somehow. The break only stops the iteration, BUT invalid input = no recipes on the interface (which should still have all the recipes) and if it's correct input = no recipe match cos it obviously breaks where it isn't receiving the code to display the recipes.

    /**
         * Searches the cakes using the search string
         * @param searchString
         * list of keywords to be searched in a cake recipe
         */
        private void searchAll(String searchString) 
        {
            if(searchString.isEmpty())
            {
                createCenterPanel();
            }
            else 
            {
                ArrayList<CakeRecipe> searchRecipe = new ArrayList<>();
                centerPanel.removeAll();
                String[] keys = searchString.split(" ");
     
                for(CakeRecipe recipe : recipeSet.getAllCakeRecipes()) 
                {
                    if(recipe.foundWords(keys) != true) 
                    {
                        JOptionPane.showMessageDialog(this,"No recipe containing search words found.", "Error!",
                                                        JOptionPane.ERROR_MESSAGE);
     
                    }
                    else
                    {
                       searchRecipe.add(recipe); 
                    }
                    break;
                }
                Collections.sort(searchRecipe);

Similar Threads

  1. Collecting user input error
    By SkyVar in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 19th, 2013, 09:48 PM
  2. Telling the user they left their input blank **GUI**
    By Grot in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 17th, 2013, 05:36 PM
  3. Replies: 2
    Last Post: September 11th, 2012, 04:10 PM
  4. Need help with user input/output for GUI.
    By Tctwins in forum AWT / Java Swing
    Replies: 6
    Last Post: February 20th, 2012, 04:13 PM
  5. help with a error message
    By JavaNoob82 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 23rd, 2010, 02:56 PM