Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author user */ //package mongodb.Conn; import com.mongodb.BasicDBObject; import com.mongodb.*; import com.sun.media.jfxmedia.events.NewFrameEvent; import java.awt.*; import javax.swing.JOptionPane; public class login_page extends javax.swing.JFrame { String userid, password, submit; int radio_check = -99; /** * Creates new form login_page */ public login_page() { initComponents(); /* long startTime = System.nanoTime(); System.out.println(startTime); */ } /** * 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); UserID = new java.awt.TextField(); Password = new java.awt.TextField(); Login = new java.awt.Button(); admin_radio_button = new javax.swing.JRadioButton(); emp_radio_button = new javax.swing.JRadioButton(); jLabel5 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setBackground(new java.awt.Color(0, 102, 153)); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel1.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 255, 255)); jLabel1.setText("Pay & Park "); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 100, 300, 60)); jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setText("User ID : "); getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 260, 84, -1)); jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N jLabel3.setForeground(new java.awt.Color(255, 255, 255)); jLabel3.setText("Password : "); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 320, -1, -1)); UserID.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR)); UserID.setText("pratham84"); UserID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { UserIDActionPerformed(evt); } }); getContentPane().add(UserID, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 260, 150, 30)); Password.setEchoChar('*'); Password.setName(""); // NOI18N Password.setText("ust"); Password.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PasswordActionPerformed(evt); } }); getContentPane().add(Password, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 320, 150, 30)); Login.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N Login.setLabel("Login"); Login.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { LoginActionPerformed(evt); } }); getContentPane().add(Login, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 390, 97, 45)); admin_radio_button.setBackground(new java.awt.Color(0, 0, 0)); buttonGroup1.add(admin_radio_button); admin_radio_button.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N admin_radio_button.setForeground(new java.awt.Color(255, 255, 255)); admin_radio_button.setText("Administrator"); admin_radio_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { admin_radio_buttonActionPerformed(evt); } }); getContentPane().add(admin_radio_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 180, -1, -1)); emp_radio_button.setBackground(new java.awt.Color(0, 0, 0)); buttonGroup1.add(emp_radio_button); emp_radio_button.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N emp_radio_button.setForeground(new java.awt.Color(255, 255, 255)); emp_radio_button.setText("Employee"); emp_radio_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { emp_radio_buttonActionPerformed(evt); } }); getContentPane().add(emp_radio_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(630, 180, -1, -1)); jLabel5.setIcon(new javax.swing.ImageIcon( "C:\\Users\\user\\Desktop\\DBMS Project\\Parking_Project\\Images\\90.jpg")); // NOI18N getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(-80, -110, -1, -1)); pack(); }// </editor-fold>//GEN-END:initComponents private void UserIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UserIDActionPerformed // TODO add your handling code here: }//GEN-LAST:event_UserIDActionPerformed private void LoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoginActionPerformed // TODO add your handling code here: try { int check = 0; userid = UserID.getText(); password = Password.getText(); submit = Login.getActionCommand(); if (radio_check == -99) JOptionPane.showMessageDialog(null, "Please Chhose Admin/Employee"); else { if (radio_check == 0) { if ((userid.equals("admin")) && (password.equals("password123"))) { System.out.println("Done"); //TO connect theses two pages.. setVisible(false); new Admin_rights().setVisible(true); } else { JOptionPane.showMessageDialog(null, "Invalid Admin Login"); } } else { MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("employee_info"); /*ISERT DOCUMENT BasicDBObject doc = new BasicDBObject("userid",userid).append("password",password); collection.insert(doc); */ DBCursor cursor = collection.find(); DBObject obj; String temp_user, temp_pass; while (cursor.hasNext()) { obj = (DBObject) cursor.next(); temp_user = obj.get("_id").toString(); temp_pass = obj.get("password").toString(); if ((userid.equals(temp_user)) && (password.equals(temp_pass))) { System.out.println("Done"); //TO connect theses two pages.. setVisible(false); /*new Vehicle_type_check().setVisible(true);*/ new Entry_OR_Exit().setVisible(true); check = 1; break; } } if (check != 1) { JOptionPane.showMessageDialog(null, "Authentication Failed!\nInvalid Login"); } } } } catch (Exception e) { } }//GEN-LAST:event_LoginActionPerformed private void PasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PasswordActionPerformed // TODO add your handling code here: }//GEN-LAST:event_PasswordActionPerformed private void admin_radio_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_admin_radio_buttonActionPerformed // TODO add your handling code here: radio_check = 0; }//GEN-LAST:event_admin_radio_buttonActionPerformed private void emp_radio_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emp_radio_buttonActionPerformed // TODO add your handling code here: radio_check = 1; }//GEN-LAST:event_emp_radio_buttonActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(login_page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(login_page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(login_page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(login_page.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new login_page().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private java.awt.Button Login; private java.awt.TextField Password; private java.awt.TextField UserID; private javax.swing.JRadioButton admin_radio_button; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JRadioButton emp_radio_button; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel5; // End of variables declaration//GEN-END:variables }