Académique Documents
Professionnel Documents
Culture Documents
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
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);
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();
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) {
// 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]);
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"));
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)