//Custom button text
// Neh = 1 (ok) - button right
// Aneyoh = 0 (cancel) button left
import javax.swing.*;
class ConfirmationDialogCustomButtonText
{
public static void main( String[] args )
{
Object[] options = {"Neh!",
"Aneyoh!"};
int n = JOptionPane.showOptionDialog(null,
"Would you like green eggs and ham?",
"A Silly Question",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //do not use a custom Icon
options, //the titles of buttons
options[0]); //default button title
System.out.println(" n = " + n);
}
}
========================================================
// OK and Cancel only
import javax.swing.*;
class ConfirmationDialogBoxOKCANCEL
{
public static void main(String[] args)
{
int selection=0;
while (true)
{
selection = JOptionPane.showConfirmDialog(null,
"Play Another Game again again",
"ConfirmationWindowTitle",
JOptionPane.OK_CANCEL_OPTION);
if (selection == JOptionPane.OK_OPTION)
{
JOptionPane.showMessageDialog(null, "You clicked on OK");
}
if (selection == JOptionPane.CANCEL_OPTION)
{
JOptionPane.showMessageDialog(null, "You clicked on CANCEL");
break;
}
}
}
}