QTLoginFrame

From FinMath

Jump to: navigation, search

/*

* QTLoginFrame.java
*
* Created on March 17, 2008, 10:10 PM
*/

package QTIB;

/**

* To connect to the database
*/

import java.sql.*; import java.util.*;

/**

*
* @author  Rahul Maurya
*/

public class QTLoginFrame extends javax.swing.JFrame {

   QTWrapper jQTWrapper;
   /** Creates new form QTLoginFrame */
   public QTLoginFrame(QTWrapper iQTWrapper) {
       jQTWrapper = iQTWrapper;
       initComponents();
       this.setVisible(true);
   }
   
   /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
   // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
   private void initComponents() {
       jPasswordField = new javax.swing.JPasswordField();
       jLoginField = new javax.swing.JFormattedTextField();
       jLoginLabel = new javax.swing.JLabel();
       jPassLabel = new javax.swing.JLabel();
       jConnectLabel = new javax.swing.JLabel();
       jConnectButton = new javax.swing.JButton();
       jConnectStatusLabel = new javax.swing.JLabel();
       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
       setTitle("Connecting To The Tick Database");
       setBackground(javax.swing.UIManager.getDefaults().getColor("Table.selectionBackground"));
       jPasswordField.setText("jPasswordField1");
       jPasswordField.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               jPasswordFieldActionPerformed(evt);
           }
       });
       jLoginField.setText("admin");
       jLoginField.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               jLoginFieldActionPerformed(evt);
           }
       });
       jLoginLabel.setText("Login");
       jPassLabel.setText("Password");
       jConnectLabel.setBackground(java.awt.Color.darkGray);
       jConnectLabel.setText("Connect to the Ticks Database");
       jConnectButton.setText("Connect");
       jConnectButton.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               jConnectButtonActionPerformed(evt);
           }
       });
       jConnectStatusLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
       jConnectStatusLabel.setText("Not Connected");
       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addContainerGap(23, Short.MAX_VALUE)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                   .addComponent(jConnectLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                   .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                           .addComponent(jLoginLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                           .addComponent(jPassLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                       .addGap(18, 18, 18)
                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                           .addComponent(jPasswordField, javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(jLoginField, javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(jConnectButton, javax.swing.GroupLayout.Alignment.LEADING))))
               .addGap(50, 50, 50))
           .addComponent(jConnectStatusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
       );
       layout.setVerticalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addContainerGap()
               .addComponent(jConnectLabel)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLoginField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(jLoginLabel))
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(jPassLabel))
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addComponent(jConnectButton)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
               .addComponent(jConnectStatusLabel)
               .addGap(22, 22, 22))
       );
       pack();
   }// </editor-fold>                        
   private void jLoginFieldActionPerformed(java.awt.event.ActionEvent evt) {                                            
       // TODO add your handling code here:
       // MAKE THIS BEAUTIFUL LATER

}

   private void jConnectButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
      /**
        * Connect to the stocks database
        */
       boolean isConnected = false;
       try { 
           System.out.println("Attempting to load the driver! "); 
           jLoginString = jLoginField.getText();
           jPasswdString = new String(jPasswordField.getPassword());
           isConnected = jQTWrapper.ConnectToDB(jLoginString,jPasswdString);   
           
       } catch (Exception e) { 
           System.err.println("Got an exception! "); 
           System.err.println(e.getMessage()); 
           jConnectStatusLabel.setText("Unable to Connect");
           isConnected = false;
       }
       if (isConnected)
       {
           jConnectStatusLabel.setText("Connected!");
           this.setVisible(false);
       }
       //parent.inform( evt );

}

   private void jPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {                                               
       // TODO add your handling code here:
       

}


   // Variables declaration - do not modify                     
   private javax.swing.JButton jConnectButton;
   private javax.swing.JLabel jConnectLabel;
   private javax.swing.JLabel jConnectStatusLabel;
   private javax.swing.JFormattedTextField jLoginField;
   private javax.swing.JLabel jLoginLabel;
   private javax.swing.JLabel jPassLabel;
   private javax.swing.JPasswordField jPasswordField;
   // End of variables declaration                   
   private String jLoginString;
   private String jPasswdString;

}

Personal tools