Java Program Using Joptionpane Code
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.
C#, JAVA,PHP, Programming,Source Code Add And Update A JTable Row Using JOptionPane showInputDialog In Java Add And Update A JTable Selected Row java jtable jtable add row jtable update row row JAVA - How To Add And Update A JTable Row Using JOptionPane showInputDialog In Java.
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);
}
}
- 4 Contributors
- forum 7 Replies
- 1,729 Views
- 2 Years Discussion Span
- commentLatest Postby peter_budoLatest Post
Ezzaral2,714
Well, you can't quite work with a custom input dialog like that. There is a way to do it with an Object array for responses, but if you want radio buttons you need to create your own custom dialog. Just for the heck of it, I wrote up one way you could put this all together with JDialogs. Of course, you could probably do it a bit easier with a simple panel. Perhaps this will give you some ideas to work from (the simple BoxLayout is pretty awful)