第一次写博客!不足之处还请指出!
搜了很多博客,收集了showMassageDialog的几种参数表达格式:
完整代码:

   package 课后题测试;
    import javax.swing.*;
    public class 测试类 extends JFrame {
       public static void main(String[] args) {
	     JFrame a=new JFrame();
	     a.setTitle("a");
	     a.setVisible(true);
	     a.setSize(400,500);
		 a.setLocation(200,100);	
		 JFrame b=new JFrame();
		 b.setTitle("b");
		 b.setVisible(true);
		 b.setSize(400,500);
		 b.setLocation(600,200);	
		 JOptionPane.showMessageDialog(b,"请输入正确的商品编号(介于0~999,包含0和999)!");
		}
}

运行结果为:
JOptionPane.showMassageDialog的各种形式
一种格式为:showMassageDialog(Component parentComponent, String message),即只有父组件和提示信息,默认第三个参数为:
“消息”,默认第四个参数为:“JOptionPane.INFORMATION_MESSAGE”
例如:

JOptionPane.showMessageDialog(null,"提示信息");

运行结果:
JOptionPane.showMassageDialog的各种形式
完整格式为:showMassageDialog(Component parentComponent, String message ,String title,int messageType)
参数:
Component parentComponent:父组件;
String message:要显示的提示信息;
String title:对话框标题;
int messageType:对话框提示信息类型
参数举例及含义:

(父组件)上面完整代码的父组件为窗体b,则显示在窗体b的上面;
若父组件为null,即没有父组件,显示在屏幕中央;有时候父组件为this,则表示父组件为该代码的主窗体。

对话框提示信息类型有五种:(对于同样的语句只改变第四个参数)

 JOptionPane.showMessageDialog(null,"请输入正确的商品编号(介于0~999,包含0和999)!","确定",参数4);		
				①JOptionPane.INFORMATION_MESSAGE
				②JOptionPane.WARNING_MESSAGE
				③JOptionPane.ERROR_MESSAGE
				④JOptionPane.QUESTION_MESSAGE
				⑤JOptionPane.PLAIN_MESSAGE

第一种如下图:
JOptionPane.showMassageDialog的各种形式
第二种如下图:
JOptionPane.showMassageDialog的各种形式
第三种如下图:
JOptionPane.showMassageDialog的各种形式
第四种如下图:
JOptionPane.showMassageDialog的各种形式
第五种如下图(注意:没有小图标了):
JOptionPane.showMassageDialog的各种形式

相关文章:

  • 2021-12-04
  • 2021-05-11
  • 2022-02-24
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
猜你喜欢
  • 2022-01-24
  • 2022-02-04
  • 2022-12-23
  • 2021-05-12
  • 2021-04-29
  • 2021-09-26
  • 2021-06-21
相关资源
相似解决方案