18.online quiz


import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Javaeg extends JFrame implements ActionListener
{
Container c;
int i;
JLabel l1,l2,l3,l4;
JButton b;
JRadioButton r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16;
ButtonGroup t1,t2,t3,t4;
JPanel p1,p2,p3,p4,p5;
GridLayout g1,g2;
Javaeg()
{
String[] s1=new String[4];
String[] s2=new String[4];
String[] s3=new String[4];
String[] s4=new String[4];
String[] s5=new String[4];
String[] s6=new String[4];
c=getContentPane();

try{
Class.forName(“java.sql.Driver”);
Connection con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/new?zeroDateTimeBehavior=convertToNull”,”root”,””);
Statement s=con.createStatement();

ResultSet rs=s.executeQuery(“select * from test”);
i=-1;
while(rs.next())
{
i++;
//System.out.println(rs.getString(1));
s1[i]=rs.getString(“qname”);
//System.out.println(s1[i]);
s2[i]=rs.getString(“o1”);
//System.out.println(s2[i]);
s3[i]=rs.getString(“o2”);
//System.out.println(s3[i]);
s4[i]=rs.getString(“o3”);
//System.out.println(s4[i]);
s5[i]=rs.getString(“o4”);
//System.out.println(s5[i]);
s6[i]=rs.getString(“a1”);
//System.out.println(s6[i]);
}
l1=new JLabel(s1[0]);
l2=new JLabel(s1[1]);
l3=new JLabel(s1[2]);
l4=new JLabel(s1[3]);

b=new JButton(“Result”);

r1=new JRadioButton(s2[0]);
r1.setActionCommand(s2[0]);
r2=new JRadioButton(s3[0]);
r2.setActionCommand(s3[0]);
r3=new JRadioButton(s4[0]);
r3.setActionCommand(s4[0]);
r4=new JRadioButton(s5[0]);
r4.setActionCommand(s5[0]);
t1=new ButtonGroup();
t1.add(r1);
t1.add(r2);
t1.add(r3);
t1.add(r4);

r5=new JRadioButton(s2[1]);
r5.setActionCommand(s2[1]);
r6=new JRadioButton(s3[1]);
r6.setActionCommand(s3[1]);
r7=new JRadioButton(s4[1]);
r7.setActionCommand(s4[1]);
r8=new JRadioButton(s5[1]);
r8.setActionCommand(s5[1]);
t2=new ButtonGroup();
t2.add(r5);
t2.add(r6);
t2.add(r7);
t2.add(r8);

r9=new JRadioButton(s2[2]);
r9.setActionCommand(s2[2]);
r10=new JRadioButton(s3[2]);
r10.setActionCommand(s3[2]);
r11=new JRadioButton(s4[2]);
r11.setActionCommand(s4[2]);
r12=new JRadioButton(s5[2]);
r12.setActionCommand(s5[2]);
t3=new ButtonGroup();
t3.add(r9);
t3.add(r10);
t3.add(r11);
t3.add(r12);

r13=new JRadioButton(s2[3]);
r13.setActionCommand(s2[3]);
r14=new JRadioButton(s3[3]);
r14.setActionCommand(s3[3]);
r15=new JRadioButton(s4[3]);
r15.setActionCommand(s4[3]);
r16=new JRadioButton(s5[3]);
r16.setActionCommand(s5[3]);
t4=new ButtonGroup();
t4.add(r13);
t4.add(r14);
t4.add(r15);
t4.add(r16);

p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();

g1=new GridLayout(2,2);
g2=new GridLayout(9,1);

b.addActionListener(this);

p1.setLayout(g1);
p1.add(r1);
p1.add(r2);
p1.add(r3);
p1.add(r4);

p2.setLayout(g1);
p2.add(r5);
p2.add(r6);
p2.add(r7);
p2.add(r8);

p3.setLayout(g1);
p3.add(r9);
p3.add(r10);
p3.add(r11);
p3.add(r12);

p4.setLayout(g1);
p4.add(r13);
p4.add(r14);
p4.add(r15);
p4.add(r16);

p5.setLayout(new FlowLayout());
p5.add(b);

setLayout(g2);
add(l1);
add(p1);
add(l2);
add(p2);
add(l3);
add(p3);
add(l4);
add(p4);
add(p5);
setSize(300,300);
setTitle(“Online test”);
setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rs.close();
s.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}

public void actionPerformed (ActionEvent e)
{
int c=0,d=0,f=0,h=0;
/*
System.out.println(“Selected Radio Button: ” + t1.getSelection().getActionCommand());
System.out.println(“Selected Radio Button: ” + t2.getSelection().getActionCommand());
System.out.println(“Selected Radio Button: ” + t3.getSelection().getActionCommand());
System.out.println(“Selected Radio Button: ” + t4.getSelection().getActionCommand());
*/

if(t1.getSelection().getActionCommand().equals(“b)16 bit”))
c=10;

if(t2.getSelection().getActionCommand().equals(“a)0”))
d=10;

if(t3.getSelection().getActionCommand().equals(“b)false”))
f=10;

if(t4.getSelection().getActionCommand().equals(“a)row”))
h=10;

c=c+d+f+h;
//System.out.println(“count= “+c);
JOptionPane.showMessageDialog(null,”count= “+c);
}

public static void main(String []args)
{
new Javaeg();
}
}