gpt4 book ai didi

java - ShowMessageDialog - 组件

转载 作者:行者123 更新时间:2023-11-30 07:42:19 25 4
gpt4 key购买 nike

我想我的问题对你来说很简单。我最近开始编程。我想确切地知道它在 showMesageDialog(null,"string") 的 null 中做了什么。

我总是看到有人设置为null,但我不知道为什么要设置null。

我举个例子。

希望你能帮助我。

"JOptionPane.showMessageDialog(null, "ERROR DE PENSION");"

//1. Definicion de variables


int pension;
String categoria;
Double Promedio;
Double Descuento;

categoria = txtTP.getText().toString();
System.out.println("hola" +categoria);
if (categoria.equalsIgnoreCase("A"))
pension = 550;

else
if(categoria.equalsIgnoreCase("B"))
pension = 500;

else
if(categoria.equalsIgnoreCase("C"))
pension = 460;
else
if (categoria.equalsIgnoreCase("D"))
pension = 400;
else
pension = 0;
JOptionPane.showMessageDialog(null, "ERROR DE PENSION");

最佳答案

根据 JOptionPane 的 Javadocs:

public static void showMessageDialog(Component parentComponent, Object message)

第一个参数是父组件。根据文档:

(Parent Component) determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used

因此,通过放置 null,您可以告诉它只使用默认框架。

关于java - ShowMessageDialog - 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54873994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com