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.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.MongoClient; import java.net.UnknownHostException; import javax.swing.table.DefaultTableModel; public class emp_detail_table extends javax.swing.JFrame { /** * Creates new form emp_detail_table */ public emp_detail_table() { initComponents(); display_table(); } public void display_table() { try { MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("employee_info"); DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); DBCursor cursor = collection.find(); jTable1.setShowGrid(true); while (cursor.hasNext()) { DBObject temp = cursor.next(); model.addRow(new Object[] { temp.get("name"), temp.get("_id"), temp.get("password"), temp.get("mobileno") }); } // else if(input.equalsIgnoreCase("")==true) // JOptionPane.showMessageDialog(rootPane, "Error:: Enter a product name"); // else // JOptionPane.showMessageDialog(rootPane, "Product not found"); // } catch (UnknownHostException e) { e.getMessage(); } } /** * 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() { jLabel3 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jButton1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel3.setIcon(new javax.swing.ImageIcon( "C:\\Users\\user\\Desktop\\DBMS Project\\Parking_Project\\Images\\5.jpg")); // NOI18N setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jTable1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jTable1.setForeground(new java.awt.Color(255, 0, 0)); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Name", "User ID", "Password", "Contact" }) { boolean[] canEdit = new boolean[] { false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane1.setViewportView(jTable1); getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 590, 250)); jButton1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N jButton1.setText("Done"); jButton1.setBorder(null); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 350, 87, 33)); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 0, 0)); jLabel1.setText("Employee Details"); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 190, 31)); getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 10, -1, -1)); jLabel4.setIcon(new javax.swing.ImageIcon( "C:\\Users\\user\\Desktop\\DBMS Project\\Parking_Project\\Images\\5.jpg")); // NOI18N getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 625, 440)); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: setVisible(false); new Admin_rights().setVisible(true); }//GEN-LAST:event_jButton1ActionPerformed /** * @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(emp_detail_table.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(emp_detail_table.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(emp_detail_table.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(emp_detail_table.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 emp_detail_table().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; // End of variables declaration//GEN-END:variables }