【弹出对话框,输入内容】1.JOptionPane.showInputDialog(null,提示的内容);
2.
JOptionPane.showInputDialog(null,提示的内容,“窗名",JOptionPane.INFORMATION_MESSAGE);
3.选项有可以下拉的菜单出现:
或者
String n = (String)JOptionPane.showInputDialog(null, "Do you like turtles??",
"I like turtles", JOptionPane.QUESTION_MESSAGE, icon, options, options[0]);
第一个参数:null;
第二个参数:问题;
第三个参数:窗头;
第四个参数:JOptionPane.QUESTION_MESSAGE
第五个参数: null或者icon;
第六个参数: 可选的数组名;
第七个参数: 默认的组的第几个;
【直接弹出对话框】JOptionPane.showMessageDialog(null, "输出的内容");
【弹出与输入内容有关系的对话框】
以输入圆半径,得到面积以及周长为例:
String r = JOptionPane.showInputDialog("请输入圆的半径") ;
double r2 = Double.valueOf(r);
JOptionPane.showInternalConfirmDialog(null, "半径:"+r+"\n圆的周长为:"+String.format("%.2f",Math.PI*2*r2)+"\n圆的面积为:"+String.format("%.2f",Math.PI*r2*r2));
attenttion:String.format("%.2f",Math.PI*2*r2)为了保留俩位有效数字!