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. */ package Pennyworth; import static Pennyworth.OPERATIONS.Cashinfo; import static Pennyworth.OPERATIONS.PropertyType; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.MongoClient; import com.mongodb.*; import java.net.UnknownHostException; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import java.awt.EventQueue; import java.awt.List; import java.lang.management.OperatingSystemMXBean; import java.util.ArrayList; import javax.swing.DefaultComboBoxModel; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; public class propertydetails extends javax.swing.JFrame { static String PropertyType, PropertyDesc; static int OriginalPropertyValue; static int CurrentPropertyValue; static int PropertyArea; static int CurrentRate; static String PropertyName; static String PropertyLocation; static int ConfirmVal = -1; public propertydetails() { 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() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); txtProppertyDesc = new javax.swing.JTextArea(); btnAddProperty = new javax.swing.JButton(); ComboPropertyType = new javax.swing.JComboBox(); jLabel6 = new javax.swing.JLabel(); txtPropertyName = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); txtOriginalPrice = new javax.swing.JTextField(); ComboPropertyLocation = new javax.swing.JComboBox(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); txtPropertyArea = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); txtCurrentValue = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txtCurrentRate = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 36)); // NOI18N jLabel1.setText("Property Details"); jLabel2.setText("Property Type "); jLabel4.setText("Property Description"); txtProppertyDesc.setColumns(20); txtProppertyDesc.setRows(5); jScrollPane1.setViewportView(txtProppertyDesc); btnAddProperty.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N btnAddProperty.setText("Add Property"); btnAddProperty.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddPropertyActionPerformed(evt); } }); ComboPropertyType.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "Housing", "Land", "Commercial", "Other", " " })); jLabel6.setText("Property Name"); jLabel8.setText("Property Location"); ComboPropertyLocation.setModel( new javax.swing.DefaultComboBoxModel(new String[] { "Please Select Location (Maharashtra Only)", "Mumbai", "Aurangabad", "Nashik", "Amaravati", "Pune", "Nagpur", "Kolhapur", "Jalgaon" })); ComboPropertyLocation.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ComboPropertyLocationActionPerformed(evt); } }); jLabel10.setText("Original Buying Price"); jLabel11.setText("Property area(in Sqft)"); txtPropertyArea.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { txtPropertyAreaFocusLost(evt); } }); jLabel12.setText("Current Rate(per Sqft)"); jLabel3.setText("Current Value"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout .createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1).addGap(127, 127, 127)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addGap(20, 20, 20).addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup( jPanel1Layout.createSequentialGroup().addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( txtCurrentValue, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel10) .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE) .addGroup(jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtCurrentRate, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ComboPropertyType, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(txtOriginalPrice) .addComponent(txtPropertyArea) .addComponent( jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ComboPropertyLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtPropertyName, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addGap(67, 67, 67)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(176, 176, 176) .addComponent(btnAddProperty, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addGap(38, 38, 38) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(ComboPropertyType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(txtPropertyName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8).addComponent(ComboPropertyLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10) .addComponent(txtOriginalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(25, 25, 25) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11).addComponent(txtPropertyArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(25, 25, 25) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel12).addComponent(txtCurrentRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(96, 96, 96) .addComponent(jLabel4)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(36, 36, 36) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtCurrentValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addGap(18, 18, 18).addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(33, 33, 33).addComponent(btnAddProperty).addContainerGap(48, Short.MAX_VALUE))); jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Pennyworth/icon-buildings.png"))); // NOI18N jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Pennyworth/41469-200.png"))); // NOI18N jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Pennyworth/choosing_home_small.png"))); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(141, 141, 141) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 111, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(163, 163, 163))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(22, 22, 22) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(201, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGap(31, 31, 31).addComponent(jLabel7).addGap(58, 58, 58) .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(44, 44, 44).addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(259, 259, 259))); pack(); }// </editor-fold>//GEN-END:initComponents private void btnAddPropertyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddPropertyActionPerformed ConfirmVal = -1; try { MongoClient mongoClient = new MongoClient("localhost", 27017); // CREATING THE MONGO CLIENT OBJECT DB db = mongoClient.getDB("PENNYWORTH"); // Object to access the database // CHOOSING THE COLLECTION DBCollection coll_bank = db.getCollection("PENNYWORTH_BANKS"); DBCollection coll = db.getCollection("PENNYWORTH_USERS"); PropertyType = (String) ComboPropertyType.getSelectedItem(); PropertyDesc = txtProppertyDesc.getText(); PropertyName = txtPropertyName.getText(); OriginalPropertyValue = Integer.parseInt(txtOriginalPrice.getText()); txtCurrentValue.setEditable(false); PropertyArea = Integer.parseInt(txtPropertyArea.getText()); PropertyLocation = (String) ComboPropertyLocation.getSelectedItem(); DBObject curUser = new BasicDBObject("UserName", Mint_login.login_username); // ADDING CONTENT TO A PARTICULAR FIELD DBObject listItem = new BasicDBObject("PropertyDetails", new BasicDBObject("PropertyType", PropertyType).append("PropertyName", PropertyName) .append("PropertyDescription", PropertyDesc) .append("PropertyOriginalValue", OriginalPropertyValue) .append("PropertyCurrentValue", CurrentPropertyValue) .append("PropertyArea", PropertyArea).append("PropertyLocation", PropertyLocation)); DBObject updateQuery = new BasicDBObject("$push", listItem); coll.update(curUser, updateQuery); // JOptionPane.showMessageDialog(DateCombo,"Your Property Details Are Added to Your Pennyworth Account"); OPERATIONS.reterive(); this.dispose(); } catch (UnknownHostException ex) { Logger.getLogger(Mint_login.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_btnAddPropertyActionPerformed private void ComboPropertyLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboPropertyLocationActionPerformed if (ComboPropertyLocation.getSelectedIndex() == 1) { CurrentRate = 3000; txtCurrentRate.setText("" + CurrentRate); } if (ComboPropertyLocation.getSelectedIndex() == 2) { CurrentRate = 2000; txtCurrentRate.setText("" + CurrentRate); } if (ComboPropertyLocation.getSelectedIndex() == 3) { CurrentRate = 1200; txtCurrentRate.setText("" + CurrentRate); } if (ComboPropertyLocation.getSelectedIndex() == 4) { CurrentRate = 2200; txtCurrentRate.setText("" + CurrentRate); } if (ComboPropertyLocation.getSelectedIndex() == 5) { CurrentRate = 2400; txtCurrentRate.setText("" + CurrentRate); } if (ComboPropertyLocation.getSelectedIndex() == 6) { CurrentRate = 900; txtCurrentRate.setText("" + CurrentRate); } if (ComboPropertyLocation.getSelectedIndex() == 7) { CurrentRate = 1000; txtCurrentRate.setText("" + CurrentRate); } if (ComboPropertyLocation.getSelectedIndex() == 8) { CurrentRate = 1800; txtCurrentRate.setText("" + CurrentRate); } }//GEN-LAST:event_ComboPropertyLocationActionPerformed private void txtPropertyAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPropertyAreaFocusLost if (ComboPropertyLocation.getSelectedIndex() == 1) { CurrentRate = 3000; } if (ComboPropertyLocation.getSelectedIndex() == 2) { CurrentRate = 2000; } if (ComboPropertyLocation.getSelectedIndex() == 3) { CurrentRate = 1200; } if (ComboPropertyLocation.getSelectedIndex() == 4) { CurrentRate = 2200; } if (ComboPropertyLocation.getSelectedIndex() == 5) { CurrentRate = 2400; } if (ComboPropertyLocation.getSelectedIndex() == 6) { CurrentRate = 900; } if (ComboPropertyLocation.getSelectedIndex() == 7) { CurrentRate = 1000; } if (ComboPropertyLocation.getSelectedIndex() == 8) { CurrentRate = 1800; } PropertyArea = Integer.parseInt(txtPropertyArea.getText()); CurrentPropertyValue = CurrentRate * PropertyArea; txtCurrentValue.setText("" + CurrentPropertyValue); }//GEN-LAST:event_txtPropertyAreaFocusLost /** * * * @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(propertydetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(propertydetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(propertydetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(propertydetails.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 propertydetails().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables public javax.swing.JComboBox ComboPropertyLocation; public javax.swing.JComboBox ComboPropertyType; public javax.swing.JButton btnAddProperty; public javax.swing.JLabel jLabel1; public javax.swing.JLabel jLabel10; public javax.swing.JLabel jLabel11; public javax.swing.JLabel jLabel12; public javax.swing.JLabel jLabel2; public javax.swing.JLabel jLabel3; public javax.swing.JLabel jLabel4; public javax.swing.JLabel jLabel5; public javax.swing.JLabel jLabel6; public javax.swing.JLabel jLabel7; public javax.swing.JLabel jLabel8; public javax.swing.JLabel jLabel9; public javax.swing.JPanel jPanel1; public javax.swing.JScrollPane jScrollPane1; public javax.swing.JTextField txtCurrentRate; public javax.swing.JTextField txtCurrentValue; public javax.swing.JTextField txtOriginalPrice; public javax.swing.JTextField txtPropertyArea; public javax.swing.JTextField txtPropertyName; public javax.swing.JTextArea txtProppertyDesc; // End of variables declaration//GEN-END:variables }