Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.*;
- class NewClass4 extends JFrame {
- JTextArea t0, t1, t2, t3, t4;
- JRadioButton r1, r2, r3, r4;
- JLabel l, l5, l1, l2, l3, l4, l6, l7;
- JButton b1, b2;
- JScrollPane p;
- JPanel jp;
- String s = "ERROR!!";
- static int i = 0;
- public NewClass4() {
- Container cp;
- JFrame f = new JFrame("Teacher Interface");
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- cp = f.getContentPane();
- JPanel jp = new JPanel();
- i++;
- 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 = "insert into questions (sno, question, o1, o2, o3, o4, copt, subj)"
- + " values (?, ?, ?, ?, ?, ?, ?, ?)";
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- String s = "Subject";
- f.setSize(610, 320);
- l6 = new JLabel(s);
- l6.setBounds(40, 10, 140, 40);
- l5 = new JLabel("Question " + i);
- l5.setBounds(100, 30, 140, 40);
- t0 = new JTextArea(8, 30);
- preparedStmt.setString(2, "Question Text");
- p = new JScrollPane(t0);
- p.setHorizontalScrollBarPolicy(
- JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- p.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
- p.setBounds(20, 60, 555, 50);
- t1 = new JTextArea();
- // preparedStmt.setString(3,t1.getText());
- t1.setBounds(45, 143, 110, 22);
- t2 = new JTextArea();
- preparedStmt.setString(4, t2.getText());
- t2.setBounds(180, 143, 110, 22);
- t3 = new JTextArea(2, 10);
- preparedStmt.setString(5, t3.getText());
- t3.setBounds(315, 143, 110, 22);
- t4 = new JTextArea(2, 10);
- t4.setBounds(450, 143, 110, 22);
- preparedStmt.setString(6, t4.getText());
- l = new JLabel("Correct Option :");
- l.setBounds(150, 190, 100, 15);
- l1 = new JLabel("A");
- l1.setBounds(30, 140, 110, 25);
- l2 = new JLabel("B");
- l2.setBounds(165, 140, 110, 25);
- l3 = new JLabel("C");
- l3.setBounds(300, 140, 110, 25);
- l4 = new JLabel("D");
- l4.setBounds(435, 140, 110, 25);
- l7 = new JLabel(s);
- r1 = new JRadioButton("A");
- r1.setBounds(255, 190, 40, 15);
- r1.setBackground(Color.WHITE);
- r2 = new JRadioButton("B");
- r2.setBounds(295, 190, 40, 15);
- r2.setBackground(Color.WHITE);
- r3 = new JRadioButton("C");
- r3.setBounds(335, 190, 40, 15);
- r3.setBackground(Color.WHITE);
- r4 = new JRadioButton("D");
- r4.setBounds(375, 190, 40, 15);
- r4.setBackground(Color.WHITE);
- // f.add(js);
- jp.add(l6);
- jp.add(p);
- jp.add(l5);
- jp.add(l1);
- jp.add(t1);
- jp.add(l2);
- jp.add(t2);
- jp.add(l3);
- jp.add(t3);
- jp.add(l4);
- jp.add(l7);
- jp.add(t4);
- 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);
- b1 = new JButton("Next");
- b1.setBounds(120, 230, 100, 30);
- b1.setBackground(Color.WHITE);
- jp.add(b1);
- b1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- // String n=t1.getText();
- // String n1=t2.getText();
- // String n2=t3.getText();
- // String n3=t4.getText();
- // if(e.getSource()==b1){
- // if(n.isEmpty()==true&&n1.isEmpty()==true&&n2.isEmpty()==true&&n3.isEmpty()==true){
- // l7.setBounds(120,250,110,25);
- // jp.add(l7);
- //
- // }
- String f2 = t1.getText();
- String f1 = t2.getText();
- String f3 = t3.getText();
- String f4 = t4.getText();
- try {
- preparedStmt.setInt(1, i);
- preparedStmt.setString(2, t0.getText());
- preparedStmt.setString(3, f2);
- // t2 = new JTextArea();
- preparedStmt.setString(4, f1);
- // t3 = new JTextArea(2, 10);
- preparedStmt.setString(5, f3);
- // t4 = new JTextArea(2, 10);
- preparedStmt.setString(6, f4);
- if (r1.isSelected())
- preparedStmt.setInt(7, 1);
- else if (r2.isSelected())
- preparedStmt.setInt(7, 2);
- else if (r3.isSelected())
- preparedStmt.setInt(7, 3);
- else
- preparedStmt.setInt(7, 0);
- preparedStmt.setString(8, "NULL");
- preparedStmt.execute();
- t2.setText(f1);
- t3.setText(f3);
- t4.setText(f4);
- } catch (Exception e1) {
- System.err.println("Got an exception!");
- System.err.println(e1.getMessage());
- }
- cp.setVisible(false);
- NewClass4 obj = new NewClass4();
- dispose();
- }
- });
- b2 = new JButton("Finish");
- b2.setBounds(350, 230, 100, 30);
- b2.setBackground(Color.WHITE);
- jp.add(b2);
- b2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- f.setVisible(false);
- NewClass12 obj = new NewClass12();
- dispose();
- }
- });
- jp.setLayout(null);
- jp.setBackground(Color.BLUE);
- f.setVisible(true);
- cp.add(jp);
- // cp.setSize(610, 320);
- } catch (Exception e) {
- System.err.println("Got an exception!");
- System.err.println(e.getMessage());
- }
- }
- }
- import javax.swing.JFrame;
- class runningTeacher { //Driver for Class4
- public static void main(String[] args) {
- NewClass4 obj = new NewClass4();
- obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Add Comment
Please, Sign In to add comment