try with
key = JOptionPane.showInputDialog(popup, "Enter key", null);
instead of
String popup2 = JOptionPane.showInputDialog(popup, "Enter key", null);
You are not updating the key
again.
--EDIT--
Try this one also
String key = null;
do {
key = JOptionPane.showInputDialog(popup, "Enter key", null);
} while (key.length() != 1);