Can you try this one using JOptionPane.showConfirmDialog()
int value = JOptionPane.showConfirmDialog(frame,
"Would you like to save before opening a new file?", "New Document",
JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
In this case you don't need to close it. It will be automatically closed once any button is clicked.
For more info have a look at How to Make Dialogs.