Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 需要帮助向用户显示列表并使用Swing获取他们的响应吗_Java_Swing_User Interface_Joptionpane - Fatal编程技术网

Java 需要帮助向用户显示列表并使用Swing获取他们的响应吗

Java 需要帮助向用户显示列表并使用Swing获取他们的响应吗,java,swing,user-interface,joptionpane,Java,Swing,User Interface,Joptionpane,这是我正在做的演讲的第二部分 String temp; // Create the class Hello helloUser = new Hello(); //Get the users name temp = JOptionPane.showInputDialog("Please enter your name?"); helloUser.setName(temp); String hello = helloUser.name(helloUser.getName()); //Gree

这是我正在做的演讲的第二部分

String temp;

// Create the class
Hello helloUser = new Hello();

//Get the users name
temp = JOptionPane.showInputDialog("Please enter your name?");
helloUser.setName(temp);

String hello = helloUser.name(helloUser.getName());

//Greet the user
temp = JOptionPane.showInputDialog(null, hello, "Feeling", 
        JOptionPane.QUESTION_MESSAGE, null, new Object[]{
            "Great", "Good", "Been Better"
        });
helloUser.setFeeling(temp);
在我得到用户名后,我希望程序向他们打招呼并询问他们的情况,然后为他们提供一个选项,供他们选择答案。上面用于问候用户的代码不断向我显示此错误:

找不到适合showInputDialog(、String、String、int、Object[])方法JOptionPane的方法。showInputDialog(组件、对象、String、int、图标、Object[],Object)不适用(实际参数列表和形式参数列表长度不同)


我想给用户一个列表来选择,并将他们的选择存储在temp中。我可以用JOptionPane做这个吗?如果是这样,怎么办?

也许您忘记了参数。发件人:

showInputDialog(组件父组件、对象消息、字符串标题、int messageType、图标图标、对象[]选择值、对象初始选择值)


initialSelection值。

您当前的参数列表不适合提供的任何重载的
JOptionPane.showInputDialog()
方法

如果提供了
selectionValues
参数,则还必须提供
initialValue

请尝试以下方法:

Object[] options = {"Great", "Good", "Been Better"};
temp = JOptionPane.showInputDialog(null, 
                                   hello, 
                                   "Feeling", 
                                   JOptionPane.QUESTION_MESSAGE, 
                                   null,  
                                   options, 
                                   options[0]);

我修复了这个部分:JOptionPane.showInputDialog(null,hello,“Feeling”,JOptionPane.QUESTION_MESSAGE,null,new Object[]{“Great”,“Good”,“Been Better”});当我尝试将它分配给temp时,它仍然会给我一个错误。如何将用户的选择分配给temp?在我键入一个可能的解决方案时,我想到了添加toString()的方法。我将尝试这样做。在showInputDialog()方法之外创建对象数组,并将initialSelectionValue引用到数组中的字符串。可能它没有找到初始对象(除了相同的内容之外,这些字符串不是相同的对象)。我理解你关于对象数组的意思。但是我不理解数组中字符串的第二部分。“字符串”==“字符串”不是真的,因为它们不是相同的对象(即使它们具有相同的内容)。我的意思就是杰森·布劳特的回答。