JOptionPane

1.1 showMessageDialog

  1. JOptionPane.showMessageDialog(null, "友情提示");

image.png

  1. JOptionPane.showMessageDialog(jPanel, "提示消息", "标题",JOptionPane.WARNING_MESSAGE);

image.png

  1. JOptionPane.showMessageDialog(null, "提示消息.", "标题",JOptionPane.ERROR_MESSAGE);

image.png

1.2 showOptionDialog

  1. int n = JOptionPane.showConfirmDialog(null,
  2. "你高兴吗?",
  3. "标题",
  4. JOptionPane.YES_NO_OPTION);
  5. //n = 0/1

image.png

  1. Object[] options ={ "好啊!", "去一边!" };
  2. int m = JOptionPane.showOptionDialog(null,
  3. "我可以约你吗?",
  4. "标题",
  5. JOptionPane.YES_NO_OPTION,
  6. JOptionPane.QUESTION_MESSAGE,
  7. null,
  8. options,
  9. options[0]);

image.png

1.3 showInoutDialog

  1. Object[] obj2 ={ "足球", "篮球", "乒乓球" };
  2. String s = (String) JOptionPane.showInputDialog(null,
  3. "请选择你的爱好:\n",
  4. "爱好",
  5. JOptionPane.PLAIN_MESSAGE,
  6. new ImageIcon("icon.png"),
  7. obj2, "足球");
  8. System.out.println(s);
  1. String title = JOptionPane.showInputDialog(null,
  2. "请输入:\n",
  3. "title",
  4. JOptionPane.PLAIN_MESSAGE);
  5. System.out.println(title);

image.png

image.png