Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOptionPane showOptionDialog

I want to create a showOptionDialog using JOptionPane that has two buttons: Metric and Imperial.
If say, Metric is clicked on, the Metric GUI will load. Conversely, if Imperial is clicked on, then the Imperial GUI will load.

How do I do this?

like image 612
Jonny Stewart Avatar asked Dec 12 '22 20:12

Jonny Stewart


1 Answers

int choice = JOptionPane.showOptionDialog(null, //Component parentComponent
                               "Metric or Imperial?", //Object message,
                               "Choose an option", //String title
                               JOptionPane.YES_NO_OPTION, //int optionType
                               JOptionPane.INFORMATION_MESSAGE, //int messageType
                               null, //Icon icon,
                               {"Metric","Imperial"}, //Object[] options,
                               "Metric");//Object initialValue 
if(choice == 0 ){
   //Metric was chosen
}else{
   //Imperial was chosen
}
like image 88
gadeynebram Avatar answered Dec 14 '22 10:12

gadeynebram