This is the hardest thing I have tried yet. I am not adding ti as part of the main programme I am doing at the moment cus otherwise it would be too hard to debug. So I have created this as a separate file. I am trying to get a Joptionpane to show ask a question with 2 radio buttons to select the answer. IF the correct answer is shown then another JOptionpane will show saying correct. I also have with this a way to record correct questions you will understand better from the code. once the correct or incorrect box for selecting the wrong answer shows then when the user presses okay it goes to the next question. I am only starting with two questions to keep it simple then once thats mastered I will create 40. anyway here is my code. so anything I am doing wrong or need to do please show me. my biggest problem is an error saying incompatible types. it is cus I am trying to make an equal between a radiobutton and a string but I dont know how else to do it.
import javax.swing.*;
public class QuizFourBib
{
public static void main (String args[])
{
int res = 0;
JRadioButton dav = new JRadioButton("David");
JRadioButton saul = new JRadioButton("saul");
String ques1 = JOptionPane.showInputDialog(null,"who killed goliath?"+dav+saul,"question1",JOptionPane.QUESTION_MESSAGE);
if (ques1 == dav)
{
res=res+1;
}
else if (ques1 == saul)
{
res=res+0;
JOptionPane.showMessageDialog(null,"hard luck","",JOptionPane.INFORMATION_MESSAGE);
}
JRadioButton egypt = new JRadioButton("egypt");
JRadioButton samaria = new JRadioButton("samaria");
String ques2 = JOptionPane.showInputDialog(null,"where was moses born?"+egypt+samaria,"question1",JOptionPane.QUESTION_MESSAGE);
if (ques2 == egypt)
{
res=res+1;
}
else if (ques2 == samaria)
{
res=res+0;
JOptionPane.showMessageDialog(null,"hard luck","",JOptionPane.INFORMATION_MESSAGE);
}
System.out.println(res);
}
}