int dialogResult = JOptionPane.showConfirmDialog(frame, "Text", "Title", JOptionPane.YES_NO_OPTION); if(dialogResult == JOptionPane.YES_OPTION){ // Do something }