joption confirm dialog code example

Example 1: joptionpane.showconfirmdialog yes no example

int answer = JOptionPane.showConfirmDialog(parentComponent, 
		"Your message goes here", "Your title goes here", 
        JOptionPane.YES_NO_OPTION);

if (answer == JOptionPane.NO_OPTION) {
	// do something
} else if(answer == JOptionPane.YES_OPTION) {
  	// do something else
}

Example 2: java confirmation dialog

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

Tags:

Java Example