如何使用java弹出消息提示框

如何使用java弹出消息提示框

使用之前需要用这行代码来导入库:

import javax.swing.JOptionPane;

主要用到以下四种消息提示框:

  • showConfirmDialog(); 确认对话框

  • showInputDialog(); 输入对话框

  • showMessageDialog(); 消息对话框

  • showOptionDialog(); 选择对话框

主要有五种消息类型,类型不同,图标不同:

  • ERROR_MESSAGE

  • INFORMATION_MESSAGE

  • WARNING_MESSAGE

  • QUESTION_MESSAGE

  • PLAIN_MESSAGE

通过调用不同方法,并输入不同参数可以得到不同的对话框

参数及其含义:

parentComponent 对话框所在的容器

message 提示消息

title 标题

optionType 选择按钮类型

messageType 消息类型

icon 自定义消息图标

initialSelectionValue 默认选项或信息

selectionValues 选择选项

options 操作选项

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有六种参数设置类型

  1.  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)

下一个文章将会发表实例。

转载:https://www.cnblogs.com/zhaostudy/p/16714060.html 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值