消息提示对话框主要通过JOptionPane类的showMessageDialog来实现,主要用于信息提示、报警提示、错误提示等。
一、重载方法:
JOptionPane.showMessageDialog(Component parentComponent, Object message)
JOptionPane.showMessageDialog(Component parentComponent, Object message, String title, int messageType)
JOptionPane.showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon)
二、参数介绍:
parentComponent:指示对话框的父窗口对象,一般为当前窗口。也可以为 null 即采用缺省的 Frame 作为父窗口,此时对话框将设置在屏幕的正中。
message:指示要在对话框内显示的描述性的文字,即提示或报警的内容。
title:对话框标题栏要显示的文本。
messageType:主要决定对话框显示的图标类型,主要包括以下几种:ERROR_MESSAGE(错误提示)、INFORMATION_MESSAGE(信息提示)、WARNING_MESSAGE(报警提示)、QUESTION_MESSAGE(问题提示)、PLAIN_MESSAGE(无图标),默认为JOptionPane.INFORMATION_MESSAGE。
icon:对话框中要显示的图标,会替代messageType所代表的图标。
三、使用及举例:
JOptionPane.showMessageDialog(null, "MessageDialog");
JOptionPane.showMessageDialog(null, "MessageDialog", "这是消息对话框的标题", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "MessageDialog", "这是消息对话框的标题", JOptionPane. ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "MessageDialog", "这是消息对话框的标题", JOptionPane.INFORMATION_MESSAGE, ICON);