The easiest way to create a Yes/No/Cancel dialog box is to use showConfirmDialog(Component, Object) method of JOptionPane class.

The following example uses a confirm dialog box with a text message and stores response in the response variable:

 int response;

   response = JOptionPane.showConfirmDialog(null, "Should i delete all files?");