Java Dialog Box - Code Keeps on going....I need it to stop until someone clicks OK

When this dialog box in my code is triggered, the pop-up shows up, but users can ignore it, hit enter a bunch of times, and it seems the code continues on, leaving the "OK" button showing.  I don't want to the code to proceed further until someone clicks OK.  How? (in Java)

if (animal.contains("*")) {
                 
                  // Remvoes *s from alert
                  alert = animal.replace("*", "");
                 
                  frame.setAlwaysOnTop(true);
                 
                  JOptionPane.showMessageDialog(frame, alert);
                 
                  animal = inFS.nextLine();
               }
               // Else just read next line
               else {
                 
                  animal = inFS.nextLine();
               }
LVL 1
NAMEWITHELD12Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
That seems strange since JOptionPane is modal by default:

All dialogs are modal. Each showXxxDialog method blocks the caller until the user's interaction is complete.
(JOptionPane API docs)

Can you post a self-contained runnable example that demonstrates the problem?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NAMEWITHELD12Author Commented:
I should probably be a bit more clear in my question, actually, now that I realize it.  The loop that prints text stops until the "OK" is clicked.  That part works.

But if I go back and click in the text area and hit enter a bunch of times to produce blank spaces, and THEN I click OK, those blank lines are read in to my scnr.nextLine() producing some really unexpected results.
0
CEHJCommented:
You really need to produce runnable code
0
NAMEWITHELD12Author Commented:
I was able to fix it by just eliminating my friendly "Please enter an option." statement so that a user could hit "Enter" as many times as they wanted and the scanner.nextLine() after the pop-up would not accept the "Enter" as its entry and crash the program.  Thanks for the details on modal!
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
NetBeans

From novice to tech pro — start learning today.