JOptionPane.showMessageDialog为什么它是ERROR?

时间:2014-10-15 03:41:07

标签: java swing joptionpane

import javax.swing.JOptionPane;

public class finals {

    public static void main(String[] args) {

        String text = "";
        boolean test = false;


        text = JOptionPane.showInputDialog("Input a or b: ");

        for(int i = 0; i<text.length(); i++)
        {
            if(text.charAt(i) == 'a' || text.charAt(i) == 'b')
                {
                    test = true;
                } 

            else 
                {
                    test = false;
                    break;
                }
        }

        if(test == true) {

        text = text.replace("a", "o");
        text = text.replace("b", "1");

        JOptionPane.showMessageDialog(null,text, "Tan awa :)", JOptionPane.ERROR_MESSAGE);

        }

        if(test == false) {

----->  JOptionPane.showMessageDialog(null, "DILI MAGPATAKA :)", JOptionPane.ERROR_MESSAGE); 

        }
    }

}

2 个答案:

答案 0 :(得分:2)

您错过了title(或可能是message参数)

JOptionPane.showMessageDialog(null, "DILI MAGPATAKA :)", JOptionPane.ERROR_MESSAGE);

应该更像......

JOptionPane.showMessageDialog(null, "This is some text", "DILI MAGPATAKA :)", JOptionPane.ERROR_MESSAGE);

或其他一些,取决于你想说的是什么......

答案 1 :(得分:2)

JOptionPane.showMessageDialog(null,"DILI MAGPATAKA :)",JOptionPane.ERROR_MESSAGE);

您正在将3输入参数解析为showMessageDialog()showMessageDialog()中没有匹配方法。

仅提供以下方法。

showMessageDialog(Component parentComponent,Object message)

showMessageDialog(Component parentComponent, Object message, String title, int essageType)

showMessageDialog(Component parentComponent,
    Object message, String title, int messageType, Icon icon)