Java中,类似Windows中MessageBox的使用,用到了JOptionPane类。
利用JOptionPane类中的各个static方法生成了各种类型的对话框。这些对话框都是模式对话框。具体的方法有:
ConfirmDialog ---确认对话框,提出问题,由用户来选择回答,对话框有Yes/No按钮;
InputDialog ---提示输入文本的对话框;
MessageDialog -- 仅显示一些信息;
OptionDialog ---组合了以上三个对话框。
函数原型:
int javax.swing.JOptionPane.showConfirmDialog(Component parentComponent, Object message, String title, int optionType) throws HeadlessException
参数:
parentComponent
- determines the
Frame
in which the dialog is displayed; if
null
, or if the
parentComponent
has no
Frame
, a default
Frame
is used
message