Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.sql.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- public class JavaApplication16 {
- public static void main(String[] args) {
- sam obj = new sam();
- obj.setVisible(true);
- obj.setSize(610, 320);
- obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- obj.setLayout(null);
- obj.setTitle("Student Interface");
- }
- }
- class sam extends JFrame {
- // JTextArea t0,t1,t2,t3,t4;
- JRadioButton r1, r2, r3, r4;
- JLabel l, l5, l1, l2, l3, l4, qq, oo1, oo2, oo3, oo4;
- String q, o1, o2, o3, o4;
- JButton b1, b2;
- JScrollPane p;
- static int i = 0;
- static int lastques = 10;
- JScrollPane pane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- public sam() {
- i++;
- Container cp;
- cp = getContentPane();
- JPanel jp = new JPanel();
- try {
- // create a mysql database connection
- String myDriver = "com.mysql.jdbc.Driver";
- String myUrl = "jdbc:mysql://localhost:3307/quiz";
- Class.forName(myDriver);
- Connection conn = DriverManager.getConnection(myUrl, "root", "");
- //String query = "select * from questions";
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery("select * from questions");
- l5 = new JLabel("Question " + i);
- l5.setBounds(250, 10, 140, 40);
- q = rs.getString("question");
- qq = new JLabel(q);
- qq.setBounds(20, 60, 555, 50);
- o1 = rs.getString("o1");
- oo1 = new JLabel(o1);
- oo1.setBounds(45, 132, 110, 22);
- o2 = rs.getString("o2");
- oo2 = new JLabel(o2);
- oo2.setBounds(180, 132, 110, 22);
- o3 = rs.getString("o3");
- oo3 = new JLabel(o3);
- oo3.setBounds(315, 132, 110, 22);
- o4 = rs.getString("o4");
- oo4 = new JLabel(o4);
- oo4.setBounds(450, 132, 110, 22);
- l = new JLabel("Correct Option :");
- l.setBounds(150, 190, 100, 15);
- l1 = new JLabel("A) ");
- l1.setBounds(30, 131, 110, 25);
- l2 = new JLabel("B) ");
- l2.setBounds(165, 131, 110, 25);
- l3 = new JLabel("C) ");
- l3.setBounds(300, 131, 110, 25);
- l4 = new JLabel("D) ");
- l4.setBounds(435, 131, 110, 25);
- r1 = new JRadioButton("A");
- r1.setBounds(255, 190, 40, 15);
- r2 = new JRadioButton("B");
- r2.setBounds(295, 190, 40, 15);
- r3 = new JRadioButton("C");
- r3.setBounds(335, 190, 40, 15);
- r4 = new JRadioButton("D");
- r4.setBounds(375, 190, 40, 15);
- // f.add(js);
- b1 = new JButton("Next");
- b1.setBounds(120, 230, 100, 30);
- b1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- sam ob = new sam();
- ob.setVisible(true);
- ob.setSize(610, 320);
- ob.setLayout(null);
- ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- dispose();
- }
- });
- jp.add(l5);
- jp.add(qq);
- jp.add(l1);
- jp.add(oo1);
- jp.add(l2);
- jp.add(oo2);
- jp.add(l3);
- jp.add(oo3);
- jp.add(l4);
- jp.add(oo4);
- jp.add(l);
- jp.add(r1);
- jp.add(r2);
- jp.add(r3);
- jp.add(r4);
- ButtonGroup bg = new ButtonGroup();
- bg.add(r1);
- bg.add(r2);
- bg.add(r3);
- bg.add(r4);
- if (i != lastques) {
- jp.add(b1);
- conn.close();
- } // }
- b2 = new JButton("Finish");
- b2.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e) {
- // menu obj = new menu();
- }
- });
- b2.setBounds(350, 230, 100, 30);
- jp.add(b2);
- // f.setLayout(new FlowLayout());
- setLayout(null);
- setVisible(true);
- jp.setLayout(null);
- setVisible(true);
- // cp.add(jp);
- jp.setSize(610, 320);
- add(jp);
- } catch (Exception e) {
- System.err.println("Got an exception!");
- System.err.println(e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment