最近主要学习Swing的知识,经常用到消息提示框,经常忘记他们的用法,现在写个博客供自己和大家参考,主要分为以下三种形式:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "我是普通提示框!╮(╯▽╰)╭");
JOptionPane.showMessageDialog(null, "我是警告提示框!╮(╯▽╰)╭", "标题",JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(null, "我是错误提示框!╮(╯▽╰)╭", "标题",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "我是最基本提示框!╮(╯▽╰)╭", "标题",JOptionPane.PLAIN_MESSAGE);
int n = JOptionPane.showConfirmDialog(null, "你会了吗?", "标题",JOptionPane.YES_NO_OPTION); //返回值为0或1
Object[] options ={ "必须是", "当然是" }; //自定义按钮上的文字
int m = JOptionPane.showOptionDialog(null, "钓鱼岛是中国的吗?", "标题",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
Object[] obj2 ={ "路人甲", "路人乙", "路人丙" };
String s = (String) JOptionPane.showInputDialog(null,"请选择你的身份:\n", "身份", JOptionPane.PLAIN_MESSAGE, new ImageIcon("icon.png"), obj2, "足球");
JOptionPane.showInputDialog(null,"请输入:\n","title",JOptionPane.PLAIN_MESSAGE);