Guest User

Untitled

a guest
Oct 18th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionListener;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8. import java.awt.event.ActionEvent;
  9.  
  10. public class NewClass7 extends JFrame {
  11. JLabel l1, l2, l3, l4, l5, l6;
  12. JLabel ll3, ll4, ll5, ll6;
  13. String name, enroll, sub = "Math", date;
  14. JPanel jp;
  15. JButton b;
  16. final int total = 10;
  17. int obtained;
  18.  
  19. public NewClass7() {
  20. Container c;
  21. c = getContentPane();
  22. setLayout(null);
  23. try {
  24. // create a mysql database connection
  25. String myDriver = "com.mysql.jdbc.Driver";
  26. String myUrl = "jdbc:mysql://localhost:3307/quiz";
  27. Class.forName(myDriver);
  28. Connection conn = DriverManager.getConnection(myUrl, "root", "");
  29. String query = "select * from student";
  30. Statement st = conn.createStatement();
  31. ResultSet rs = st.executeQuery(query);
  32. rs.first();
  33. name = rs.getString("sname");
  34. enroll = rs.getString("enroll");
  35. //sub = rs.getString("subject");
  36. date = rs.getString("date");
  37. obtained = (rs.getInt("q1") +rs.getInt("q2") +rs.getInt("q3") +rs.getInt("q4") +rs.getInt("q5") +
  38. rs.getInt("q10") +rs.getInt("q9") +rs.getInt("q8") +rs.getInt("q7") +rs.getInt("q6"));
  39. String s1 = date.substring(0, 2);
  40. String s2 = date.substring(2, 4);
  41. String s3 = date.substring(4, 8);
  42. date = s1 + "/" + s2 + "/" + s3;
  43.  
  44. jp = new JPanel();
  45. l1 = new JLabel("Score obtained");
  46. l1.setFont(new Font("Ariel", Font.ITALIC, 25));
  47. l1.setBounds(75, 50, 200, 50);
  48.  
  49. l2 = new JLabel(obtained + "/" + total);
  50. l2.setFont(new Font("Ariel", Font.BOLD, 45));
  51.  
  52. if ((obtained * 100) / (total * 10) > 4) {
  53. l2.setForeground(Color.GREEN);
  54. } else {
  55. l2.setForeground(Color.RED);
  56. }
  57. l2.setBounds(115, 140, 150, 50);
  58.  
  59. l3 = new JLabel("Student Name :");
  60. l3.setBounds(40, 270, 130, 25);
  61. l4 = new JLabel("Enrollment Number :");
  62. l4.setBounds(40, 295, 130, 25);
  63. l5 = new JLabel("Subject :");
  64. l5.setBounds(40, 320, 130, 25);
  65. l6 = new JLabel("Date :");
  66. l6.setBounds(42, 345, 130, 25);
  67. ll3 = new JLabel(name);
  68. ll3.setBounds(200, 270, 130, 25);
  69. ll4 = new JLabel(enroll);
  70. ll4.setBounds(200, 295, 130, 25);
  71. // l3.setBounds(300,400,100,25);
  72. ll5 = new JLabel(sub);
  73. ll5.setBounds(200, 320, 130, 25);
  74. ll6 = new JLabel(date);
  75. ll6.setBounds(200, 345, 130, 25);
  76.  
  77. b = new JButton("OK");
  78. b.addActionListener(new ActionListener()
  79.  
  80. {
  81.  
  82. public void actionPerformed(ActionEvent e) {
  83.  
  84. menu obj = new menu();
  85. }
  86. });
  87. b.setBounds(110, 415, 100, 30);
  88. jp.add(b);
  89. jp.add(l1);
  90. // jp.add(i1);
  91. jp.add(l2);
  92. jp.add(ll3);
  93. jp.add(l3);
  94. jp.add(ll4);
  95. jp.add(l4);
  96. jp.add(ll5);
  97. jp.add(l5);
  98. jp.add(l6);
  99. jp.add(ll6);
  100. jp.setLayout(null);
  101. jp.setSize(350, 500);
  102. jp.setVisible(true);
  103. add(jp);
  104. // add(c);
  105. setSize(350, 500);
  106.  
  107. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  108.  
  109. setLayout(null);
  110.  
  111. setVisible(true);
  112. } catch (Exception e) {
  113. System.err.println("Got an exception!");
  114. System.err.println(e.getMessage());
  115.  
  116. }
  117. }
  118. }
Add Comment
Please, Sign In to add comment