JOptionPane showOptionDialog [英] JOptionPane showOptionDialog

查看:316
本文介绍了JOptionPane showOptionDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用具有两个按钮的JOptionPane创建一个showOptionDialog:公制和英制.如果说度量"被单击,则将加载度量" GUI.相反,如果单击Imperial,则将加载Imperial GUI.

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? Many thanks.

推荐答案

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
}

这篇关于JOptionPane showOptionDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆