通过调用不同方法,并输入不同参数可以得到不同的对话框
JOptionPane.showConfirmDialog有四种参数设置类型
JOptionPane.showConfirmDialog(parentComponent, message)
JOptionPane.showConfirmDialog(parentComponent, message, title, optionType)
JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType)
JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType, icon)
JOptionPane.showInputDialog有六种参数设置类型
JOptionPane.showInputDialog(message);
JOptionPane.showInputDialog(parentComponent, message);
JOptionPane.showInputDialog(message, initialSelectionValue);
JOptionPane.showInputDialog(parentComponent, message, initialSelectionValue)
JOptionPane.showInputDialog(parentComponent, message, title, messageType);
JOptionPane.showInputDialog(parentComponent, message, title, messageType, icon, selectionValues, initialSelectionValue)
JOptionPane.showMessageDialog有三种参数设置
JOptionPane.showMessageDialog(parentComponent, message);
JOptionPane.showMessageDialog(parentComponent, message, title, messageType);
JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon);
JOptionPane.showOptionDialog只有一种参数设置
JOptionPane.showOptionDialog(parentComponent, message, title, optionType, messageType, icon, options, initialValue)
JOptionPane.showComfirmDialog(null,”我的新世界”);
JOptionPane.showInputDialog(null,”我的新世界”);
JOptionPane.showMessage(null,”我的新世界”);
ImageIcon icon = new ImageIcon(“image/c.jpg”);//图片的大小需要调整到合适程度
JOptionPane.showMessageDialog(null, “自定义图标”,”提示”,JOptionPane.ERROR_MESSAGE,icon);
该消息框的警示信息图标被后面的参数icon所指向的图标覆盖
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.OK_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.YES_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.YES_NO_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.NO_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.YES_NO_CANCEL_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.CANCEL_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.OK_CANCEL_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.CLOSED_OPTION);
JOptionPane.showConfirmDialog(null, “我的新世界”, “提示”,JOptionPane.DEFAULT_OPTION);
接收输入框输入的信息
String str = (String)JOptionPane.showInputDialog(null);
接收并判断点击的按钮是哪个,用int对象op接收对话框返回的值,并用if语句判断
int op = JOptionPane.showConfirmDialog(null,”新世界”,”提示”,JOptionPane.YES_NO_CANCEL_OPTION);
if(op==JOptionPane.YES_OPTION){
}else if(op==JOptionPane.NO_OPTION){
}
接收选择对话框的消息(必须用数组下标接收)
Object[] fruits = {“苹果”,”梨子”,”香蕉”,”西瓜”,”荔枝”};
int op = JOptionPane.showOptionDialog(null, “你喜欢什么水果”, “标题”,JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null, fruits, fruits[0]);
System.out.print((String)fruits[op]);
原文:https://blog.csdn.net/tjk123456/article/details/77868034