最近主要学习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);
Java消息提示框JOptionPane的使用方法介绍到这里,更多java学习请参考编程字典java教程 和问答部分,谢谢大家对编程字典的支持。
原文链接:https://blog.csdn.net/c1481118216/article/details/51921521?ops_request_misc=&request_id=&biz_id=102&utm_term=java&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~sobaiduweb~default-6-51921521.nonecase&spm=1018.2226.3001.4450