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 */ import com.mongodb.BasicDBObject; import com.mongodb.*; import com.sun.media.jfxmedia.events.NewFrameEvent; import java.awt.*; import javax.swing.JOptionPane; public class Vehicle_type_check extends javax.swing.JFrame { /** * Creates new form Vehicle_type_check */ public Vehicle_type_check() { initComponents(); } /** * 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() { bike_button = new javax.swing.JButton(); other_button = new javax.swing.JButton(); car_button = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); cancel_button = new javax.swing.JButton(); logout_button = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); bike_button.setText("Bike"); bike_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bike_buttonActionPerformed(evt); } }); getContentPane().add(bike_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 117, 86, 44)); other_button.setText("Other"); other_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { other_buttonActionPerformed(evt); } }); getContentPane().add(other_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 268, 86, 44)); car_button.setText("Car"); car_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { car_buttonActionPerformed(evt); } }); getContentPane().add(car_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 191, 86, 44)); jLabel1.setFont(new java.awt.Font("Segoe UI Emoji", 1, 24)); // NOI18N jLabel1.setText("VEHICLE SELECTION "); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(105, 29, -1, 54)); jLabel3.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.darkShadow")); jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/car.jpg"))); // NOI18N getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(166, 191, 92, 44)); cancel_button.setText("Cancel"); cancel_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancel_buttonActionPerformed(evt); } }); getContentPane().add(cancel_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(207, 318, 85, 35)); logout_button.setText("LogOut"); logout_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logout_buttonActionPerformed(evt); } }); getContentPane().add(logout_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 3, 90, 30)); pack(); }// </editor-fold>//GEN-END:initComponents private void bike_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bike_buttonActionPerformed // TODO add your handling code here: try { int count_bike; System.out.println("Hello_End"); MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_bike = obj.getInt("wheeler_2"); System.out.println(count_bike); if (count_bike < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_2", count_bike); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers"); } } catch (Exception e) { } }//GEN-LAST:event_bike_buttonActionPerformed private void other_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_other_buttonActionPerformed // TODO add your handling code here: try { int count_other; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("other", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_other = obj.getInt("other"); System.out.println(count_other); if (count_other < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("other", count_other); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("other", count_other + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking Trucks"); } } catch (Exception e) { } }//GEN-LAST:event_other_buttonActionPerformed private void car_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_car_buttonActionPerformed // TODO add your handling code here: try { int count_car; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_4", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_car = obj.getInt("wheeler_4"); System.out.println(count_car); if (count_car < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_4", count_car); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_4", count_car + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers"); } } catch (Exception e) { } }//GEN-LAST:event_car_buttonActionPerformed private void cancel_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_buttonActionPerformed // TODO add your handling code here: setVisible(false); new Entry_OR_Exit().setVisible(true); }//GEN-LAST:event_cancel_buttonActionPerformed private void logout_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logout_buttonActionPerformed // TODO add your handling code here: setVisible(false); new login_page().setVisible(true); }//GEN-LAST:event_logout_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(Vehicle_type_check.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Vehicle_type_check.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Vehicle_type_check.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Vehicle_type_check.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 Vehicle_type_check().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton bike_button; private javax.swing.JButton cancel_button; private javax.swing.JButton car_button; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; private javax.swing.JButton logout_button; private javax.swing.JButton other_button; // End of variables declaration//GEN-END:variables }