JOptionPane
是Java Swing库中的一个类,用于创建对话框(Dialogs),以便与用户进行交互。它提供了一种简单的方式来显示消息、警告、错误、输入框等。
主要方法:
showMessageDialog(Component parentComponent, Object message)
:显示一个包含消息的对话框。showInputDialog(Component parentComponent, Object message)
:显示一个带有输入框的对话框,接受用户输入。showConfirmDialog(Component parentComponent, Object message)
:显示一个包含确认按钮的对话框,通常用于确认某个操作。showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)
:显示一个带有自定义选项按钮的对话框。
参数说明:
parentComponent
:对话框的父组件,通常是一个JFrame
或JDialog
。message
:要显示的消息。title
:对话框的标题。optionType
:对话框的按钮类型,如JOptionPa