- showMessageDialog只有一个确定按钮;
JOptionPane.showMessageDialog(null,"普通提示框!","哈哈",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"警告提示框!","哈哈",JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(null,"错误提示框!","哈哈",JOptionPane.ERROR_MESSAGE);
- showOptionDialog有两个选择按钮,有返回值是int型,0或者1,0代表是,1代表否
JOptionPane.showConfirmDialog(null,"yes or no","标题",JOptionPane.YES_NO_OPTION);
Object[] options ={"不说","说"};
JOptionPane.showOptionDialog(null,"你说话呀!!","标题",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
- showInputDialog有输入列表,并且可以将你选择的那个对象返回;
Object[] objects ={"甲","乙","丙"};
String s =(String) JOptionPane.showInputDialog(null,"请选择你的身份\n","身份",JOptionPane.PLAIN_MESSAGE,newImageIcon("icon.png"), objects,"足球");
System.out.println(s);
java运行框就会出现你刚才所选择的那个对象;
String title = JOptionPane.showInputDialog(null,"请输入:\n","title", JOptionPane.PLAIN_MESSAGE);
System.out.println(title);