Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionListener;
- import java.sql.*;
- import java.util.Calendar;
- //Assuming that the data table is for question, 4 options, correct answer
- public class JavaApplication17 {
- public static void calling(String[] args) //changed class name
- {
- sam obj=new sam();
- }
- }
- class sam extends JFrame
- {
- static JTextArea t0;
- static JTextArea t1;
- static JTextArea t2;
- static JTextArea t3;
- static JTextArea t4;
- JRadioButton r1,r2,r3,r4;
- JLabel l,l5,l1,l2,l3,l4;
- JButton b;
- int i;
- JScrollPane pane= new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- public sam()
- {
- JFrame f=new JFrame("Teacher Interface");
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setLayout(new FlowLayout());
- f.setSize(600,500);
- for(i=1;i<11;i++)
- {
- l5=new JLabel("Question "+i);
- l5.setPreferredSize(new Dimension(600, 40));
- l5.setHorizontalAlignment(JLabel.CENTER);
- l5.setVerticalAlignment(JLabel.CENTER);
- t0=new JTextArea(2,52);
- t0.getText();
- t1=new JTextArea(2,10);
- t1.getText();
- t2=new JTextArea(2,10);
- t2.getText();
- t3=new JTextArea(2,10);
- t3.getText();
- t4=new JTextArea(2,10);
- t4.getText();
- l=new JLabel("Correct Option");
- l1=new JLabel("A");
- l2=new JLabel("B");
- l3=new JLabel("C");
- l4=new JLabel("D");
- r1 =new JRadioButton("A");
- r2 =new JRadioButton("B");
- r3 =new JRadioButton("C");
- r4 =new JRadioButton("D");
- f.add(l5);
- f.add(t0);
- f.add(l1);
- f.add(t1);
- f.add(l2);
- f.add(t2);
- f.add(l3);
- f.add(t3);
- f.add(l4);
- f.add(t4);
- f.add(l);
- f.add(r1);
- f.add(r2);
- f.add(r3);
- f.add(r4);
- ButtonGroup bg=new ButtonGroup();
- bg.add(r1);
- bg.add(r2);
- bg.add(r3);
- bg.add(r4);
- }
- //f.setContentPane(pane);
- b=new JButton("Submit");
- f.add(b);
- f.setVisible(true);
- }
- public static void main(String[] args)
- {
- try
- {
- // create a mysql database connection
- String myDriver = "org.gjt.mm.mysql.Driver";
- String myUrl = "jdbc:mysql://localhost/test";
- Class.forName(myDriver);
- Connection conn = DriverManager.getConnection(myUrl, "root", "");
- // the mysql insert statement
- String query = " insert into users (question, subject, option 1, option 2, option 3, option 4, correct_opt)"
- + " values (?, ?, ?, ?, ?, ?, ?)";
- // create the mysql insert preparedstatement
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- preparedStmt.setString (1, t0.getText());
- //preparedStmt.setString(2, t5.getText()); assuming t5 will be the text input for subject
- preparedStmt.setString (3, t1.getText());
- preparedStmt.setString (4, t2.getText());
- preparedStmt.setString (5, t3.getText());
- preparedStmt.setString (6, t4.getText());
- if (r1.isSelected()); // to check if the radio button selected is correct or not
- else if (r2.isSelected());
- else if (r3.isSelected());
- else if(r4.isSelected());
- //the statement will be preparedStmt.setInteger (7, w/e the integer is);
- // execute the preparedstatement
- preparedStmt.execute();
- conn.close();
- }
- catch (Exception e)
- {
- System.err.println("Got an exception!");
- System.err.println(e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment