JFrame frame = new JFrame();
Object result = JOptionPane.showInputDialog(frame, "Enter a blog website");
String word2 = (String) result;
hi, this is my coding to create a joptionpane to receive the user's input. It works perfectly fine, where i type in my input then the code process it.
However, when i close the pane, i do not know why it cannot be closed. Instead, it process the empty field and return a null value. This pane has 2 buttons. One is OK and CANCEL. The OK button works fine, the problem lies within the CANCEL button.
The Cancel button do not close the frame, instead it process the empty field and return a null value to my code. Do i miss anything on this JOptionpane coding ?
This is the intended behaviour. You have to check if result is not null:
Object result = JOptionPane.showInputDialog(frame, "Enter a blog website");
if (result != null) {
String word2 = (String) result;
}
Now nothing should be proceeded and the OptionPane should be closed: