【问题标题】:ShowMessageDialog - ComponentsShowMessageDialog - 组件
【发布时间】:2019-07-19 07:36:17
【问题描述】:

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

我总是看到人们设置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");

【问题讨论】:

  • 考虑使用 Stack Overflow 西班牙语:es.stackoverflow.com
  • 我写得太快了。抱歉说错了。
  • @Fernando.F 如果这个/任何答案对您有帮助/对您未来的读者有帮助,请支持或接受答案。见:stackoverflow.com/help/why-vote

标签: java arrays if-statement


【解决方案1】:

根据 JOptionPane 的 Javadocs:

public static void showMessageDialog(Component parentComponent, Object message)

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

(父组件)确定显示对话框的框架;如果为 null,或者如果 parentComponent 没有 Frame,则使用默认 Frame

因此,通过输入 null 来告诉它只使用默认框架。

【讨论】:

【解决方案2】:

showMessageDialog 的第一个参数指向父组件。 如果设置为 null,则您的父组件使用默认框架。 通常是桌面的中心

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    相关资源
    最近更新 更多