Guest User

Untitled

a guest
Apr 17th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.53 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package millionaire;
  7. import java.sql.*;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. /**
  11.  *
  12.  * @author Sidharth Malhotra
  13.  */
  14. public class Questions extends javax.swing.JFrame {
  15. Connection conn;
  16.     PreparedStatement ps;
  17.     ResultSet rs;
  18.     String s = "";
  19.     Statement stmt;
  20.     int id=1;
  21.    
  22.     /**
  23.      * Creates new form Questions
  24.      * @param id
  25.      */
  26.     public void GetQuestion(int id){
  27.          try {
  28.                     // action to be done every 1 second
  29.                     stmt = conn.createStatement();
  30.              
  31.                     String sql1 = "SELECT * FROM questions WHERE id"+id;
  32.                     rs = stmt.executeQuery(sql1);
  33.                    
  34.                     System.out.println(rs);
  35.                    
  36.                    
  37.                    
  38.                    
  39.                      
  40.                 } catch (SQLException ex) {
  41.                     Logger.getLogger(Questions.class.getName()).log(Level.SEVERE, null, ex);
  42.                 }
  43.                
  44.                
  45.    
  46. }
  47.     public Questions() throws ClassNotFoundException, SQLException {
  48.         initComponents();
  49.         try{
  50.             String driver = "com.mysql.jdbc.Driver";
  51.             Class.forName(driver);
  52.             conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb","root","");
  53.             System.out.println("Connected!!");
  54.             GetQuestion(id);
  55.         }
  56.         catch(ClassNotFoundException error)
  57.         {
  58.             System.out.println("Error:" + error.getMessage());
  59.            
  60.         }catch(SQLException error)
  61.         {
  62.             System.out.println("Error:" + error.getMessage());
  63.         }
  64.        
  65.        
  66.     }
  67.  
  68.     /**
  69.      * This method is called from within the constructor to initialize the form.
  70.      * WARNING: Do NOT modify this code. The content of this method is always
  71.      * regenerated by the Form Editor.
  72.      */
  73.     @SuppressWarnings("unchecked")
  74.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  75.     private void initComponents() {
  76.  
  77.         jDesktopPane1 = new javax.swing.JDesktopPane();
  78.         jLabel2 = new javax.swing.JLabel();
  79.         jLabel1 = new javax.swing.JLabel();
  80.         jLabel3 = new javax.swing.JLabel();
  81.         optionA = new javax.swing.JButton();
  82.         optionB = new javax.swing.JButton();
  83.         optionD = new javax.swing.JButton();
  84.         optionC = new javax.swing.JButton();
  85.  
  86.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  87.  
  88.         jDesktopPane1.setPreferredSize(new java.awt.Dimension(1502, 1303));
  89.  
  90.         jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Sidharth Malhotra\\Desktop\\millionaire\\QVGM_AFRIQUE_DU_SUD_DETOURE.png")); // NOI18N
  91.  
  92.         jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  93.         jLabel1.setForeground(new java.awt.Color(255, 255, 255));
  94.         jLabel1.setText("Question:");
  95.  
  96.         jLabel3.setBackground(new java.awt.Color(255, 255, 255));
  97.         jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  98.         jLabel3.setForeground(new java.awt.Color(255, 255, 255));
  99.         jLabel3.setText("Which of the following is the capital of India?");
  100.  
  101.         optionA.setBackground(new java.awt.Color(0, 0, 255));
  102.         optionA.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  103.         optionA.setForeground(new java.awt.Color(255, 255, 255));
  104.         optionA.setText("Delhi");
  105.         optionA.addActionListener(new java.awt.event.ActionListener() {
  106.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  107.                 optionAActionPerformed(evt);
  108.             }
  109.         });
  110.  
  111.         optionB.setBackground(new java.awt.Color(0, 0, 255));
  112.         optionB.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  113.         optionB.setForeground(new java.awt.Color(255, 255, 255));
  114.         optionB.setText("Jammu");
  115.         optionB.addActionListener(new java.awt.event.ActionListener() {
  116.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  117.                 optionBActionPerformed(evt);
  118.             }
  119.         });
  120.  
  121.         optionD.setBackground(new java.awt.Color(0, 0, 255));
  122.         optionD.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  123.         optionD.setForeground(new java.awt.Color(255, 255, 255));
  124.         optionD.setText("Bangalore");
  125.         optionD.addActionListener(new java.awt.event.ActionListener() {
  126.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  127.                 optionDActionPerformed(evt);
  128.             }
  129.         });
  130.  
  131.         optionC.setBackground(new java.awt.Color(0, 0, 255));
  132.         optionC.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  133.         optionC.setForeground(new java.awt.Color(255, 255, 255));
  134.         optionC.setText("Kolkata");
  135.         optionC.addActionListener(new java.awt.event.ActionListener() {
  136.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  137.                 optionCActionPerformed(evt);
  138.             }
  139.         });
  140.  
  141.         jDesktopPane1.setLayer(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
  142.         jDesktopPane1.setLayer(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
  143.         jDesktopPane1.setLayer(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
  144.         jDesktopPane1.setLayer(optionA, javax.swing.JLayeredPane.DEFAULT_LAYER);
  145.         jDesktopPane1.setLayer(optionB, javax.swing.JLayeredPane.DEFAULT_LAYER);
  146.         jDesktopPane1.setLayer(optionD, javax.swing.JLayeredPane.DEFAULT_LAYER);
  147.         jDesktopPane1.setLayer(optionC, javax.swing.JLayeredPane.DEFAULT_LAYER);
  148.  
  149.         javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
  150.         jDesktopPane1.setLayout(jDesktopPane1Layout);
  151.         jDesktopPane1Layout.setHorizontalGroup(
  152.             jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  153.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDesktopPane1Layout.createSequentialGroup()
  154.                 .addContainerGap(490, Short.MAX_VALUE)
  155.                 .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  156.                     .addGroup(jDesktopPane1Layout.createSequentialGroup()
  157.                         .addComponent(optionC, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
  158.                         .addGap(168, 168, 168)
  159.                         .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  160.                             .addComponent(optionD, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
  161.                             .addComponent(optionB, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
  162.                     .addComponent(optionA, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
  163.                     .addGroup(jDesktopPane1Layout.createSequentialGroup()
  164.                         .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
  165.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  166.                         .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 825, javax.swing.GroupLayout.PREFERRED_SIZE)))
  167.                 .addGap(61, 61, 61))
  168.             .addGroup(jDesktopPane1Layout.createSequentialGroup()
  169.                 .addGap(511, 511, 511)
  170.                 .addComponent(jLabel2)
  171.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  172.         );
  173.         jDesktopPane1Layout.setVerticalGroup(
  174.             jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  175.             .addGroup(jDesktopPane1Layout.createSequentialGroup()
  176.                 .addContainerGap()
  177.                 .addComponent(jLabel2)
  178.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  179.                 .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  180.                     .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
  181.                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  182.                 .addGap(18, 18, 18)
  183.                 .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  184.                     .addComponent(optionA, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
  185.                     .addComponent(optionB, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
  186.                 .addGap(29, 29, 29)
  187.                 .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  188.                     .addComponent(optionD, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
  189.                     .addComponent(optionC, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
  190.                 .addContainerGap(723, Short.MAX_VALUE))
  191.         );
  192.  
  193.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  194.         getContentPane().setLayout(layout);
  195.         layout.setHorizontalGroup(
  196.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  197.             .addGroup(layout.createSequentialGroup()
  198.                 .addContainerGap()
  199.                 .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1482, Short.MAX_VALUE)
  200.                 .addContainerGap())
  201.         );
  202.         layout.setVerticalGroup(
  203.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  204.             .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  205.         );
  206.  
  207.         pack();
  208.     }// </editor-fold>                        
  209.  
  210.     private void optionAActionPerformed(java.awt.event.ActionEvent evt) {                                        
  211.         // TODO add your handling code here:
  212.     }                                      
  213.  
  214.     private void optionBActionPerformed(java.awt.event.ActionEvent evt) {                                        
  215.         // TODO add your handling code here:
  216.     }                                      
  217.  
  218.     private void optionDActionPerformed(java.awt.event.ActionEvent evt) {                                        
  219.         // TODO add your handling code here:
  220.     }                                      
  221.  
  222.     private void optionCActionPerformed(java.awt.event.ActionEvent evt) {                                        
  223.         // TODO add your handling code here:
  224.     }                                      
  225.  
  226.     /**
  227.      * @param args the command line arguments
  228.      */
  229.     public static void main(String args[]) {
  230.         /* Set the Nimbus look and feel */
  231.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  232.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  233.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  234.          */
  235.         try {
  236.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  237.                 if ("Nimbus".equals(info.getName())) {
  238.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  239.                     break;
  240.                 }
  241.             }
  242.         } catch (ClassNotFoundException ex) {
  243.             java.util.logging.Logger.getLogger(Questions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  244.         } catch (InstantiationException ex) {
  245.             java.util.logging.Logger.getLogger(Questions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  246.         } catch (IllegalAccessException ex) {
  247.             java.util.logging.Logger.getLogger(Questions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  248.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  249.             java.util.logging.Logger.getLogger(Questions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  250.         }
  251.         //</editor-fold>
  252.  
  253.         /* Create and display the form */
  254.        
  255.         java.awt.EventQueue.invokeLater(new Runnable() {
  256.             public void run() {
  257.                 try {
  258.                     new Questions().setVisible(true);
  259.                 } catch (ClassNotFoundException ex) {
  260.                     Logger.getLogger(Questions.class.getName()).log(Level.SEVERE, null, ex);
  261.                 } catch (SQLException ex) {
  262.                     Logger.getLogger(Questions.class.getName()).log(Level.SEVERE, null, ex);
  263.                 }
  264.             }
  265.         });
  266.     }
  267.  
  268.     // Variables declaration - do not modify                    
  269.     private javax.swing.JDesktopPane jDesktopPane1;
  270.     private javax.swing.JLabel jLabel1;
  271.     private javax.swing.JLabel jLabel2;
  272.     private javax.swing.JLabel jLabel3;
  273.     private javax.swing.JButton optionA;
  274.     private javax.swing.JButton optionB;
  275.     private javax.swing.JButton optionC;
  276.     private javax.swing.JButton optionD;
  277.     // End of variables declaration                  
  278. }
Add Comment
Please, Sign In to add comment