在某一按钮下写下如下代码即可
int response = JOptionPane.showConfirmDialog(this, "do you want to continue action?", "confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if(response == JOptionPane.YES_OPTION)
{
System.out.println("yes option selected!");
}
else if(response == JOptionPane.NO_OPTION)
{
System.out.println("no opraton selected!");
}
else if(response == JOptionPane.CLOSED_OPTION)
{
System.out.println("close opion selected!");
}
else if(response == JOptionPane.CANCEL_OPTION)
{
System.out.println("canel selected!");
}