Please us the
code tags; I have added them so you can see how much better your post looks.
Never write
== false or similar; you can get all sorts of nasty errors if you mistakenly write = for ==. If you want something to be false you write
while (!flag) and to get it true you write
while (flag). So you can simply write
while (flag).
Lots of beginners get confused about == when using Strings. The == only tests whether the two Strings are the same object in memory; you need to use the equals() method. The String entered from the JOptionPane is not going to be the same String as "x", not even if the two have identical content. You can read about equals
here, and
here and
here.
You would do well to look through the
String class for methods which start with equals; there is another rather similar method which might be useful.