我想使用 JOptionPane 创建一个 showOptionDialog ,它有两个按钮:公制和英制。如果说,Metric 被点击,Metric GUI 将加载。相反,如果单击 Imperial,则将加载 Imperial GUI。

我该怎么做呢?
非常感谢。

最佳答案

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
}

10-07 12:51