Guest User

Untitled

a guest
Oct 17th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.sql.*;
  3.  
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10.  
  11. public class JavaApplication16 {
  12.  
  13. public static void main(String[] args) {
  14. sam obj = new sam();
  15.  
  16. obj.setVisible(true);
  17. obj.setSize(610, 320);
  18. obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  19. obj.setLayout(null);
  20. obj.setTitle("Student Interface");
  21.  
  22. }
  23. }
  24.  
  25. class sam extends JFrame {
  26.  
  27. // JTextArea t0,t1,t2,t3,t4;
  28. JRadioButton r1, r2, r3, r4;
  29. JLabel l, l5, l1, l2, l3, l4, qq, oo1, oo2, oo3, oo4;
  30. String q, o1, o2, o3, o4;
  31. JButton b1, b2;
  32. JScrollPane p;
  33. static int i = 0;
  34. static int lastques = 10;
  35. JScrollPane pane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
  36. JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  37.  
  38. public sam() {
  39. i++;
  40. Container cp;
  41. cp = getContentPane();
  42. JPanel jp = new JPanel();
  43.  
  44. try {
  45. // create a mysql database connection
  46. String myDriver = "com.mysql.jdbc.Driver";
  47. String myUrl = "jdbc:mysql://localhost:3307/quiz";
  48. Class.forName(myDriver);
  49. Connection conn = DriverManager.getConnection(myUrl, "root", "");
  50. //String query = "select * from questions";
  51. Statement st = conn.createStatement();
  52. ResultSet rs = st.executeQuery("select * from questions");
  53.  
  54. l5 = new JLabel("Question " + i);
  55. l5.setBounds(250, 10, 140, 40);
  56. q = rs.getString("question");
  57. qq = new JLabel(q);
  58.  
  59. qq.setBounds(20, 60, 555, 50);
  60.  
  61. o1 = rs.getString("o1");
  62. oo1 = new JLabel(o1);
  63. oo1.setBounds(45, 132, 110, 22);
  64.  
  65. o2 = rs.getString("o2");
  66. oo2 = new JLabel(o2);
  67. oo2.setBounds(180, 132, 110, 22);
  68.  
  69. o3 = rs.getString("o3");
  70. oo3 = new JLabel(o3);
  71. oo3.setBounds(315, 132, 110, 22);
  72.  
  73. o4 = rs.getString("o4");
  74. oo4 = new JLabel(o4);
  75. oo4.setBounds(450, 132, 110, 22);
  76.  
  77. l = new JLabel("Correct Option :");
  78. l.setBounds(150, 190, 100, 15);
  79. l1 = new JLabel("A) ");
  80. l1.setBounds(30, 131, 110, 25);
  81.  
  82. l2 = new JLabel("B) ");
  83. l2.setBounds(165, 131, 110, 25);
  84. l3 = new JLabel("C) ");
  85. l3.setBounds(300, 131, 110, 25);
  86. l4 = new JLabel("D) ");
  87. l4.setBounds(435, 131, 110, 25);
  88. r1 = new JRadioButton("A");
  89. r1.setBounds(255, 190, 40, 15);
  90. r2 = new JRadioButton("B");
  91. r2.setBounds(295, 190, 40, 15);
  92. r3 = new JRadioButton("C");
  93. r3.setBounds(335, 190, 40, 15);
  94. r4 = new JRadioButton("D");
  95. r4.setBounds(375, 190, 40, 15);
  96.  
  97. // f.add(js);
  98.  
  99. b1 = new JButton("Next");
  100. b1.setBounds(120, 230, 100, 30);
  101. b1.addActionListener(new ActionListener() {
  102.  
  103. public void actionPerformed(ActionEvent e) {
  104.  
  105. sam ob = new sam();
  106.  
  107. ob.setVisible(true);
  108. ob.setSize(610, 320);
  109.  
  110. ob.setLayout(null);
  111. ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  112. dispose();
  113. }
  114.  
  115. });
  116. jp.add(l5);
  117. jp.add(qq);
  118. jp.add(l1);
  119. jp.add(oo1);
  120.  
  121. jp.add(l2);
  122. jp.add(oo2);
  123. jp.add(l3);
  124. jp.add(oo3);
  125. jp.add(l4);
  126.  
  127. jp.add(oo4);
  128. jp.add(l);
  129. jp.add(r1);
  130. jp.add(r2);
  131. jp.add(r3);
  132. jp.add(r4);
  133.  
  134. ButtonGroup bg = new ButtonGroup();
  135. bg.add(r1);
  136. bg.add(r2);
  137. bg.add(r3);
  138. bg.add(r4);
  139. if (i != lastques) {
  140. jp.add(b1);
  141. conn.close();
  142. } // }
  143. b2 = new JButton("Finish");
  144. b2.addActionListener(new ActionListener()
  145.  
  146. {
  147.  
  148. public void actionPerformed(ActionEvent e) {
  149.  
  150. // menu obj = new menu();
  151. }
  152. });
  153. b2.setBounds(350, 230, 100, 30);
  154. jp.add(b2);
  155. // f.setLayout(new FlowLayout());
  156. setLayout(null);
  157.  
  158. setVisible(true);
  159.  
  160. jp.setLayout(null);
  161. setVisible(true);
  162. // cp.add(jp);
  163. jp.setSize(610, 320);
  164. add(jp);
  165. } catch (Exception e) {
  166. System.err.println("Got an exception!");
  167. System.err.println(e.getMessage());
  168. }
  169.  
  170. }
  171.  
  172. }
Add Comment
Please, Sign In to add comment