Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Font;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import javax.swing.table.DefaultTableModel;
- public class combinedresult {
- JFrame f;
- combinedresult() {
- 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 student";
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery(query);
- rs.first();
- f = new JFrame("Students marks");
- String sub = "Physics"; //This input has to come from another interface, not going to define it now.
- JPanel jp = new JPanel();
- jp.setSize(400, 200);
- int totques, correct;
- String[] tblHead = { "Name", "Enrollment no.", "Marks" };
- int n = 50;// dynamic, no of students to be passed
- String name[] = new String[n];
- String enroll[] = new String[n];
- int marks[] = new int[n];
- int i = 0;
- while(rs.next()) {
- // entries will be filled from the database here
- name[i] = rs.getString("sname");
- enroll[i] = rs.getString("enroll");
- marks[i] = (rs.getInt("q1") +rs.getInt("q2") +rs.getInt("q3") +rs.getInt("q4") +rs.getInt("q5") +
- rs.getInt("q10") +rs.getInt("q9") +rs.getInt("q8") +rs.getInt("q7") +rs.getInt("q6"));
- i++;
- }
- DefaultTableModel dtm = new DefaultTableModel(tblHead, 0);
- int p = 0;
- JTable jt = new JTable(dtm);
- for (int j = 0; j < i; j++) {
- dtm.insertRow(p, new Object[] { name[j], enroll[j], marks[j] });
- }
- JScrollPane sp = new JScrollPane(jt);
- JLabel l1 = l1 = new JLabel(
- " Subject : " + sub);
- l1.setFont(new Font("Arial", Font.TRUETYPE_FONT, 24));
- jp.add(sp);
- f.getContentPane().setLayout(new BorderLayout());
- f.getContentPane().add(l1, BorderLayout.NORTH);
- // f.getContentPane().add(sp,BorderLayout.CENTER);
- JButton b = new JButton("OK");
- b.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e) {
- menu obj = new menu();
- }
- });
- b.setBounds(180, 490, 100, 30);
- f.add(b);
- f.add(jp);
- f.setSize(500, 600);
- f.setVisible(true);
- f.setLayout(new BorderLayout());
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- } catch (Exception e) {
- System.err.println("Got an exception!");
- System.err.println(e.getMessage());
- }
- }
- public static void main(String[] args) {
- new combinedresult();
- }
- }
Add Comment
Please, Sign In to add comment