Quiz
Quiz
*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
JPanel panel;
JPanel panelresult;
JRadioButton choice1;
JRadioButton choice2;
JRadioButton choice3;
ButtonGroup bg;
JLabel lblmess;
JButton btnext;
String[][] qpa;
String[][] qca;
int qaid;
HashMap<Integer, String> map;
Quiz(){
initializedata();
setTitle("Quiz Program");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(430,290);
setLocation(300,100);
setResizable(false);
Container cont=getContentPane();
cont.setLayout(null);
cont.setBackground(Color.GRAY);
bg = new ButtonGroup();
choice1 = new JRadioButton("Choice1",false);
choice2 = new JRadioButton("Choice2",false);
choice3 = new JRadioButton("Choice3",false);
bg.add(choice1);
bg.add(choice2);
bg.add(choice3);
panel.add(lblmess);
panel.add(choice1);
panel.add(choice2);
panel.add(choice3);
panel.add(btnext);
cont.add(panel);
setVisible(true);
qaid=0;
readqa(qaid);
}
if(btnext.getText().equals("Next")){if(qaid<9){
map.put(qaid,getSelection());
qaid++;readqa(qaid);
}
else {
map.put(qaid,getSelection());
btnext.setText("Show answers");
}
}
choice1.setText(qpa[qid][1]);
choice2.setText(qpa[qid][2]);
choice3.setText(qpa[qid][3]);
choice1.setSelected(true);
}
}
}