Asked by Anonymous
String buttons[] = {"button1", "button2", "button3", "default"}; JOptionPane.showOptionDialog(null,"Message","Title",JOptionPane.NO_OPTION,JOptionPane.PLAIN_MESSAGE,null, buttons,"default");
whenever I type a if statement, it gives me an error under the buttons.
if (buttons = "button1"){
}
how do I make the error go away.
whenever I type a if statement, it gives me an error under the buttons.
if (buttons = "button1"){
}
how do I make the error go away.
Answers
Answered by
oobleck
<u>buttons</u> is an array. You cannot compare it to a string.
You need a separate string variable, say, <u>button</u>, to receive the input, and then you can compare.
Plus, "=" is the assignment operator. You probably meant to use "==", which is the logical comparison operator.
if (button == "button1") { ...
Clearly, you are just starting out, so be sure to consult java's excellent online documentation frequently.
You need a separate string variable, say, <u>button</u>, to receive the input, and then you can compare.
Plus, "=" is the assignment operator. You probably meant to use "==", which is the logical comparison operator.
if (button == "button1") { ...
Clearly, you are just starting out, so be sure to consult java's excellent online documentation frequently.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.