Reputation: 113
This is the second part of a presentation that I am working on.
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);
After I get the users name I want the program to greet them and ask how they are doing, then provide them a selection to choose from for the answer. The code above for greeting the user keeps giving me this error:
no suitable method found for showInputDialog(<null>,String,String,int,<null>,Object[]) method JOptionPane.showInputDialog(Component,Object,String,int,Icon,Object[],Object) is not applicable (actual and formal argument lists differ in length)
I would like to give the user a list to choose from and store their selection in temp. Can I do that with JOptionPane? If so how?
Upvotes: 0
Views: 115
Reputation: 2368
Your current parameter list does not fit any of the overloaded JOptionPane.showInputDialog()
methods provided.
If you provide the selectionValues
parameter, you must also provide initialValue
.
Try this instead:
Object[] options = {"Great", "Good", "Been Better"};
temp = JOptionPane.showInputDialog(null,
hello,
"Feeling",
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
Upvotes: 1
Reputation: 4727
Maybe you are forgeting on parameter. From JOptionPane API:
showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
initialSelection value.
Upvotes: 1