Vous êtes sur la page 1sur 8

// Save this code as Project.java import java.io.*; import java.lang.*; import java.util.*; import java.sql.*; import java.awt.

*; import java.awt.Color; import java.awt.event.*; import javax.swing.*;

public class Project { public static void main(String[] args) { MainFrame fr = new MainFrame(); } }

class MainFrame extends JFrame { private JFrame f; private JLabel l1,l2; private JButton button; private JRadioButton r1,r2,r3,r4; private ButtonGroup bg; private Container C; public int count = -1; public int[] a = new int[20];

private String UsrChoice; // Used to find User Input private String AnsChoice; // Used to find Answer from DB

public MainFrame() { super("Aptitude Examination System"); setLayout(new FlowLayout()); bg = new ButtonGroup();

f = new JFrame(); C = f.getContentPane(); C.setBackground(Color.DARK_GRAY); C.setLayout(null); f.setSize(750, 500); f.setTitle("Aptitude Examination System"); f.setVisible(true); Font f1 = new Font("Verdana", Font.BOLD, 30);

l1 = new JLabel(); l1.setFont(f1); l1.setForeground(Color.blue); l1.setText("APTITUDE EXAMINATION SYSTEM"); l1.setBounds(100, 5, 700, 100); C.add(l1);

Font f2 = new Font("Verdana", Font.PLAIN, 20);

l2 = new JLabel("");

l2.setFont(f2); l2.setForeground(Color.WHITE); l2.setText("Click Start to Begin"); l2.setBounds(75, 60, 500, 100); C.add(l2);

this.Questions();

r1 = new JRadioButton("",true); r1.setFont(f2); r1.setBounds(200, 200, 125, 50);

r2 = new JRadioButton("",false); r2.setFont(f2); r2.setBounds(450, 200, 125, 50);

r3 = new JRadioButton("", false); r3.setFont(f2); r3.setBounds(200, 280, 125, 50);

r4 = new JRadioButton("", false); r4.setFont(f2); r4.setBounds(450, 280, 125, 50);

bg.add(r1); bg.add(r2); bg.add(r3); bg.add(r4);

bg.add(r1);

button = new JButton(); button.setFont(new Font("Verdana", Font.BOLD, 25)); button.setForeground(Color.BLACK); button.setText("Start"); button.setBounds(320, 375, 120, 30); C.add(button); /* try { MF.SetQA(count); } catch (Exception e) { System.out.println(e.getMessage()); } */ buttonHandler handler = new buttonHandler(); button.addActionListener(handler); } private class buttonHandler implements ActionListener { public void actionPerformed(ActionEvent ae) { count++; if(count==0) {

C.add(r1); C.add(r2); C.add(r3); C.add(r4); }

// Set Buuton Text While Running System if(count<=18) { button.setText("Next"); //l2.setText("Question " + (count+1) + " is....." + a[count]); try { this.SetQA(a[count]); } catch (Exception e) { System.out.println(e.getMessage()); } } else if(count==19) { button.setText("Finish"); // l2.setText("Question " + (count+1) + " is....." + a[count]); try { this.SetQA(a[count]);

} catch (Exception e) { System.out.println(e.getMessage()); }

} else { System.exit(0); } } // Code to Display The Result

public void SetQA(int val) throws IOException { String str,url; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Users\\Saravanan\\Desktop\\Java\\Apti.mdb"; Connection con = DriverManager.getConnection(url); String query = " SELECT * FROM DATA WHERE ID = " + val; Statement st = con.createStatement(); ResultSet rs = st.executeQuery(query);

rs.next(); l2.setText(rs.getString("Question"));

r1.setText(rs.getString("C1")); r2.setText(rs.getString("C2")); r3.setText(rs.getString("C3")); r4.setText(rs.getString("C4")); AnsChoice = rs.getString("Answer"); System.out.println(AnsChoice);

} catch (Exception e) { System.out.println(e.getMessage()); } } }

public void Questions() { Random R = new Random(); int count = 0 ; int temp; int ChkCount; int i; while(count<20) { temp = R.nextInt(50)+1; ChkCount=0; for(i=count;i>=0;i--) if(a[i]==temp)

ChkCount++; if(ChkCount==0) { a[count]=temp; count++; } } } }

// Save this code as Project.java

Vous aimerez peut-être aussi