Skip to main content

Help with JOptionPane.showInputDialog

1 reply [Last post]
jdqvc
Offline
Joined: 2006-02-17
Points: 0

I am trying to create an input pane with multiple input messages, but having problem declaring result object.

Snipit:
private static int calcPay()
{
double rate, grossPay, taxRate, credit, netPay, finalPay;
int hours, check = 0;
String state;

JFrame inputFrame = new JFrame();
inputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object[] answers;
Object[] questions = {"Hours worked:",
"Pay Rate:",
"Home State"};
answers = JOptionPane.showInputDialog(questions);

}

Error:
C:\MyJava\Payroll.java:32: incompatible types
found : java.lang.String
required: java.lang.Object[]
answers = JOptionPane.showInputDialog(questions);
^
1 error

Tool completed with exit code 1

From API:
message
A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type:

Object[]
An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Scott Violet

Jeff,

I'm not able to reproduce this.
What JDK are you using?

-Scott