Skip to content

Instantly share code, notes, and snippets.

@zachomedia
Last active December 1, 2018 21:52
Show Gist options
  • Save zachomedia/4365663 to your computer and use it in GitHub Desktop.
Save zachomedia/4365663 to your computer and use it in GitHub Desktop.
Example demonstrating how to get the return value from a confirm dialog.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JOptionPaneExample
{
public static void main(String [] args)
{
int returnValue = 0;
returnValue = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?", "Are you sure?", JOptionPane.YES_NO_OPTION);
if (returnValue == JOptionPane.YES_OPTION)
JOptionPane.showMessageDialog(null, "Yes was clicked.");
else if (returnValue == JOptionPane.NO_OPTION)
JOptionPane.showMessageDialog(null, "No was clicked.");
}//End of main method
}//End of class
@amLiux
Copy link

amLiux commented Dec 1, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment