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 n9420924 */ import com.itextpdf.text.List; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.Element; import com.itextpdf.text.FontFactory; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.Image; import com.itextpdf.text.pdf.BarcodeEAN; import com.itextpdf.text.pdf.PdfContentByte; import java.sql.*; import java.awt.*; import java.text.MessageFormat; import javax.swing.*; import net.proteanit.sql.DbUtils; import java.util.Calendar; import java.util.Date; import java.io.*; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.design.JRDesignQuery; import net.sf.jasperreports.engine.design.JasperDesign; import net.sf.jasperreports.engine.xml.JRXmlLoader; import net.sf.jasperreports.view.JasperViewer; public class EmployeeInfo extends javax.swing.JFrame { Connection conn = null; ResultSet rs = null; PreparedStatement pst = null; /** * Creates new form EmployeeInfo */ public EmployeeInfo() { initComponents(); conn = javaconnect.ConnectDB(); update_table(); Fillcombo(); currentDate(); } public void comboselect() { int d = ComboBox_name.getSelectedIndex(); if (ComboBox_name.getSelectedItem() == "") { UserInfo_Frame s = new UserInfo_Frame(); s.setVisible(true); } if (d == 2) { Login_iframe l = new Login_iframe(); l.setVisible(true); } } public void currentDate() { Calendar greporianCalendarObject = Calendar.getInstance(); //int month = greporianCalendarObject.get(Calendar.MONTH) Date today = new Date(); menu_date.setText(String.format("%td/%tb/%tY %tT", today, today, today, today)); } private void update_table() { String sql = "select * from EmployeeInfo"; try { pst = conn.prepareStatement(sql); rs = pst.executeQuery(); Table_Employee.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex); } finally { try { rs.close(); pst.close(); //conn.close(); } catch (Exception e) { } } } private void Fillcombo() { try { String sql = "select * from EmployeeInfo"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { String name = rs.getString("FirstName"); ComboBox_name.addItem(name); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } /** * 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(); buttonGroup2 = new javax.swing.ButtonGroup(); jScrollPane1 = new javax.swing.JScrollPane(); Table_Employee = new javax.swing.JTable(); ComboBox_name = new javax.swing.JComboBox(); jToolBar1 = new javax.swing.JToolBar(); jButton1 = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); delBtn = new javax.swing.JButton(); saveBtn = new javax.swing.JButton(); newBtn = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); printBtn = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jPanel3 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); txt_empID = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); txt_lastName = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txt_age = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); txt_firstName = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jCheckBox1 = new javax.swing.JCheckBox(); jCheckBox2 = new javax.swing.JCheckBox(); jDesktopPane1 = new javax.swing.JDesktopPane(); imgageOfEmp = new javax.swing.JLabel(); jButton4 = new javax.swing.JButton(); attach_image = new javax.swing.JButton(); txt_attachImg_path = new javax.swing.JTextField(); jPanel1 = new javax.swing.JPanel(); txt_search = new javax.swing.JTextField(); jCheckBox3 = new javax.swing.JCheckBox(); jCheckBox4 = new javax.swing.JCheckBox(); jCheckBox5 = new javax.swing.JCheckBox(); jCheckBox6 = new javax.swing.JCheckBox(); jButton6 = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); jMenuItem2 = new javax.swing.JMenuItem(); jSeparator2 = new javax.swing.JPopupMenu.Separator(); jMenuItem4 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); menu_date = new javax.swing.JMenu(); jMenu3 = new javax.swing.JMenu(); jMenuItem3 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); Table_Employee.setForeground(new java.awt.Color(102, 102, 255)); Table_Employee .setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); Table_Employee.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { Table_EmployeeMouseClicked(evt); } }); jScrollPane1.setViewportView(Table_Employee); ComboBox_name.addPopupMenuListener(new javax.swing.event.PopupMenuListener() { public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) { } public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) { ComboBox_namePopupMenuWillBecomeInvisible(evt); } public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) { } }); jToolBar1.setRollover(true); jButton1.setIcon(new javax.swing.ImageIcon( "studenthome.qut.edu.au\\group24$\\n9420924\\Documents\\NetBeansProjects\\Project123\\images\\Button-Close-icon.png")); // NOI18N jButton1.setFocusable(false); jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jToolBar1.add(jButton1); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "List Of Button", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 2, 16), new java.awt.Color(51, 51, 255))); // NOI18N delBtn.setText("Delete"); delBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { delBtnActionPerformed(evt); } }); saveBtn.setBackground(new java.awt.Color(0, 255, 255)); saveBtn.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N saveBtn.setForeground(new java.awt.Color(204, 255, 51)); saveBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Save-icon.png"))); // NOI18N saveBtn.setText("Save"); saveBtn.setToolTipText("save to your table"); saveBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveBtnActionPerformed(evt); } }); newBtn.setText("New"); newBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newBtnActionPerformed(evt); } }); jButton3.setText("Clear"); jButton2.setText("Update"); jButton5.setText("Report"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(newBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(saveBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(delBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jButton5)) .addContainerGap())); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(saveBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(newBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(delBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton5))); printBtn.setText("Print"); printBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { printBtnActionPerformed(evt); } }); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Employee INFO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 16), new java.awt.Color(255, 51, 51))); // NOI18N jLabel1.setText("Employee ID"); jLabel2.setText("Name"); jLabel3.setText("Last Name"); jLabel4.setText("Age"); jLabel5.setText("Gender"); buttonGroup1.add(jCheckBox1); jCheckBox1.setText("Male"); jCheckBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBox1ActionPerformed(evt); } }); buttonGroup1.add(jCheckBox2); jCheckBox2.setText("Female"); jCheckBox2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBox2ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup().addComponent(jLabel1) .addGap(18, 18, 18)) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jLabel2).addGap(68, 68, 68))) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel3) .addGap(35, 35, 35))) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel4).addGap(81, 81, 81))) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel5).addGap(58, 58, 58))) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txt_empID, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_firstName, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_lastName, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_age, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jCheckBox1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jCheckBox2))) .addContainerGap(65, Short.MAX_VALUE))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1) .addComponent(txt_empID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(33, 33, 33) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(txt_firstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(26, 26, 26) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(txt_lastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(31, 31, 31) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(txt_age, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(jCheckBox1).addComponent(jCheckBox2)) .addContainerGap(75, Short.MAX_VALUE))); jScrollPane2.setViewportView(jPanel3); imgageOfEmp.setText("jLabel5"); javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1); jDesktopPane1.setLayout(jDesktopPane1Layout); jDesktopPane1Layout.setHorizontalGroup(jDesktopPane1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jDesktopPane1Layout.createSequentialGroup().addContainerGap() .addComponent(imgageOfEmp, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE) .addContainerGap())); jDesktopPane1Layout .setVerticalGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jDesktopPane1Layout.createSequentialGroup().addGap(25, 25, 25) .addComponent(imgageOfEmp, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(25, Short.MAX_VALUE))); jDesktopPane1.setLayer(imgageOfEmp, javax.swing.JLayeredPane.DEFAULT_LAYER); jButton4.setText("Image"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); attach_image.setText("Attach Image"); attach_image.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { attach_imageActionPerformed(evt); } }); txt_attachImg_path.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txt_attachImg_pathActionPerformed(evt); } }); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Search")); txt_search.setBackground(new java.awt.Color(0, 255, 153)); txt_search.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txt_searchActionPerformed(evt); } }); txt_search.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { txt_searchKeyReleased(evt); } }); 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(txt_search, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(txt_search, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 5, Short.MAX_VALUE))); buttonGroup2.add(jCheckBox3); jCheckBox3.setText("jCheckBox3"); buttonGroup2.add(jCheckBox4); jCheckBox4.setText("jCheckBox4"); buttonGroup2.add(jCheckBox5); jCheckBox5.setText("jCheckBox5"); buttonGroup2.add(jCheckBox6); jCheckBox6.setText("jCheckBox6"); jButton6.setText("IReport"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); jMenu1.setText("File"); jMenu1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenu1ActionPerformed(evt); } }); jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem1.setText("New"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenu1.add(jSeparator1); jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Button-Close-icon.png"))); // NOI18N jMenuItem2.setText("Close"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenu1.add(jSeparator2); jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem4.setText("Exit"); jMenuItem4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem4ActionPerformed(evt); } }); jMenu1.add(jMenuItem4); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); menu_date.setText("Date"); jMenuBar1.add(menu_date); jMenu3.setText("Help"); jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem3.setText("Help file"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu3.add(jMenuItem3); jMenuBar1.add(jMenu3); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGap(76, 76, 76).addComponent( ComboBox_name, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(65, 65, 65).addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(printBtn).addComponent(jButton4)) .addGap(45, 45, 45)) .addGroup(layout.createSequentialGroup().addGap(76, 76, 76) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(48, 48, 48).addComponent( jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton6).addGap(24, 24, 24))))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 443, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGap(40, 40, 40) .addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(53, 53, 53) .addComponent(attach_image)) .addGroup(layout.createSequentialGroup().addGap(37, 37, 37) .addComponent(txt_attachImg_path, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(18, 18, 18) .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jCheckBox3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jCheckBox5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jCheckBox6, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jCheckBox4, javax.swing.GroupLayout.Alignment.TRAILING)))))) .addGap(30, 30, 30))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup( javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(16, 16, 16).addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(31, 31, 31) .addComponent(printBtn))) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ComboBox_name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton4)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(87, 87, 87) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton6)))) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGap(31, 31, 31) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(36, 36, 36) .addComponent(attach_image) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txt_attachImg_path, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jCheckBox3).addComponent(jCheckBox4)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jCheckBox5) .addComponent(jCheckBox6)))))) .addContainerGap(212, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void Table_EmployeeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Table_EmployeeMouseClicked int row = Table_Employee.getSelectedRow(); String Table_click = (Table_Employee.getModel().getValueAt(row, 0).toString()); //System.out.println("Table_Click is: " + Table_click); // TODO add your handling code here: try { String sql = " select image from EmployeeInfo where EmployeeID = '" + Table_click + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { byte[] imagedata = rs.getBytes("image"); format = new ImageIcon(imagedata); imgageOfEmp.setIcon(format); } } catch (Exception e) { e.printStackTrace(); } try { String sql = "select * from EmployeeInfo where EmployeeID='" + Table_click + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { String empID = rs.getString("EmployeeID"); String firstName = rs.getString("FirstName"); String lastName = rs.getString("LastName"); String age = rs.getString("age"); txt_empID.setText(empID); txt_firstName.setText(firstName); txt_lastName.setText(lastName); txt_age.setText(age); // change color of text based on age int ageNumber = Integer.parseInt(age); if (ageNumber > 25) { txt_age.setBackground(Color.GREEN); txt_age.setForeground(Color.DARK_GRAY); } else txt_age.setBackground(Color.RED); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_Table_EmployeeMouseClicked private void ComboBox_namePopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_ComboBox_namePopupMenuWillBecomeInvisible String tmp = (String) ComboBox_name.getSelectedItem(); System.out.println("tmp is: " + tmp); String sql = "select * from EmployeeInfo where FirstName = ?"; try { pst = conn.prepareStatement(sql); pst.setString(1, tmp); rs = pst.executeQuery(); if (rs.next()) { String empID = rs.getString("EmployeeID"); System.out.println("empID is " + empID); String firstName = rs.getString("FirstName"); String lastName = rs.getString("LastName"); String age = rs.getString("age"); txt_empID.setText(empID); txt_firstName.setText(firstName); txt_lastName.setText(lastName); txt_age.setText(age); } else { JOptionPane.showMessageDialog(null, "Username and Password is wrong"); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_ComboBox_namePopupMenuWillBecomeInvisible private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jMenuItem1ActionPerformed private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed // TODO add your handling code here: this.dispose(); }//GEN-LAST:event_jMenu1ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed this.dispose(); }//GEN-LAST:event_jMenuItem2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed this.dispose(); }//GEN-LAST:event_jButton1ActionPerformed private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed try { String sql = "Insert into EmployeeInfo(EmployeeID,FirstName,LastName,age,image,gender) values (?,?,?,?,?,?)"; pst = conn.prepareStatement(sql); pst.setString(1, txt_empID.getText()); pst.setString(2, txt_firstName.getText()); pst.setString(3, txt_lastName.getText()); pst.setString(4, txt_age.getText()); pst.setBytes(5, person_image); pst.setString(6, gender); pst.execute(); JOptionPane.showMessageDialog(null, "Saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } update_table(); }//GEN-LAST:event_saveBtnActionPerformed private void newBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBtnActionPerformed this.dispose(); UserInfo_Frame s = new UserInfo_Frame(); s.setVisible(true); }//GEN-LAST:event_newBtnActionPerformed private void delBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delBtnActionPerformed try { String sql = "delete from EmployeeInfo where EmployeeID = ?"; pst = conn.prepareStatement(sql); pst.setString(1, txt_empID.getText()); pst.execute(); JOptionPane.showMessageDialog(null, "Deleted"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } update_table(); }//GEN-LAST:event_delBtnActionPerformed private void txt_searchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_searchKeyReleased try { String sql = "select * from EmployeeInfo where FirstName = ?"; pst = conn.prepareStatement(sql); pst.setString(1, txt_search.getText()); rs = pst.executeQuery(); if (rs.next()) { String empID = rs.getString("EmployeeID"); System.out.println("empID is " + empID); String firstName = rs.getString("FirstName"); String lastName = rs.getString("LastName"); String age = rs.getString("age"); txt_empID.setText(empID); txt_firstName.setText(firstName); txt_lastName.setText(lastName); txt_age.setText(age); } } catch (Exception e) { } }//GEN-LAST:event_txt_searchKeyReleased private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed try { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "p134-talwar.pdf"); } catch (Exception e) { } }//GEN-LAST:event_jMenuItem3ActionPerformed private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed System.exit(0); }//GEN-LAST:event_jMenuItem4ActionPerformed private void printBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printBtnActionPerformed MessageFormat header = new MessageFormat("Report Print"); MessageFormat footer = new MessageFormat("Page{0,number,integer}"); try { Table_Employee.print(JTable.PrintMode.NORMAL, header, footer); } catch (java.awt.print.PrinterException e) { System.err.format("Cannot print %s%n", e.getMessage()); } }//GEN-LAST:event_printBtnActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed try { String sql = " select image from EmployeeInfo where EmployeeID = 6 "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { byte[] imagedata = rs.getBytes("image"); format = new ImageIcon(imagedata); imgageOfEmp.setIcon(format); } } catch (Exception e) { e.printStackTrace(); } }//GEN-LAST:event_jButton4ActionPerformed private void attach_imageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_attach_imageActionPerformed JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(null); File f = chooser.getSelectedFile();//help to attach file String filename = f.getAbsolutePath(); txt_attachImg_path.setText(filename); try { File image = new File(filename); FileInputStream fis = new FileInputStream(image); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); } person_image = bos.toByteArray(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_attach_imageActionPerformed private void txt_searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_searchActionPerformed // TODO add your handling code here: }//GEN-LAST:event_txt_searchActionPerformed private void txt_attachImg_pathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_attachImg_pathActionPerformed // TODO add your handling code here: }//GEN-LAST:event_txt_attachImg_pathActionPerformed private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed gender = "male"; }//GEN-LAST:event_jCheckBox1ActionPerformed private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed gender = "female"; }//GEN-LAST:event_jCheckBox2ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed String value1 = txt_empID.getText(); String value2 = txt_firstName.getText(); String value3 = txt_lastName.getText(); String value4 = txt_age.getText(); try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Report1.pdf")); document.open(); //add barcode PdfContentByte CB = writer.getDirectContent(); BarcodeEAN codEAN = new BarcodeEAN(); codEAN.setCode("1234567891023"); //this value must be 13 digits Paragraph para = new Paragraph(); document.add(new Paragraph("Barcode UDCA")); codEAN.setCodeType(BarcodeEAN.UPCA); codEAN.setCode("1098765432112"); document.add(codEAN.createImageWithBarcode(CB, BaseColor.BLACK, BaseColor.BLACK)); document.add(para); Image image = Image.getInstance("images/Cherry.png"); document.add(new Paragraph("Image")); document.add(image); // write tile with style document.add(new Paragraph("Hello World", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); // write date document.add(new Paragraph(new Date().toString())); document.add(new Paragraph("--------------------------------------------")); PdfPTable table = new PdfPTable(2);// 2 columns // set title , column sapn, aliignment,background color PdfPCell cell = new PdfPCell(new Paragraph("Title")); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); // PdfPTable table = new PdfPTable(x); should add multiple of x table.addCell("EmployeeID"); table.addCell(value1); table.addCell("Name"); table.addCell(value2); table.addCell("Last Name"); table.addCell(value3); table.addCell("Age"); table.addCell(value4); document.add(table); List list = new List(true, 20); list.add("First Item"); list.add("Second Item"); list.add("Third Item"); list.add("Fourth Item"); document.add(list); document.close(); JOptionPane.showMessageDialog(null, "Report saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_jButton5ActionPerformed private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed try { //String report="First_report.jrxml"; JasperDesign jd = JRXmlLoader.load("First_report.jrxml"); String sql = "select * from EmployeeInfo order by age"; JRDesignQuery newQuery = new JRDesignQuery(); newQuery.setText(sql); jd.setQuery(newQuery); JasperReport jr = JasperCompileManager.compileReport(jd); JasperPrint jp = JasperFillManager.fillReport(jr, null, conn); JasperViewer.viewReport(jp); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_jButton6ActionPerformed /** * @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(EmployeeInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(EmployeeInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(EmployeeInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(EmployeeInfo.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 EmployeeInfo().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox ComboBox_name; private javax.swing.JTable Table_Employee; private javax.swing.JButton attach_image; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.ButtonGroup buttonGroup2; private javax.swing.JButton delBtn; private javax.swing.JLabel imgageOfEmp; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JCheckBox jCheckBox1; private javax.swing.JCheckBox jCheckBox2; private javax.swing.JCheckBox jCheckBox3; private javax.swing.JCheckBox jCheckBox4; private javax.swing.JCheckBox jCheckBox5; private javax.swing.JCheckBox jCheckBox6; private javax.swing.JDesktopPane jDesktopPane1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JPopupMenu.Separator jSeparator2; private javax.swing.JToolBar jToolBar1; private javax.swing.JMenu menu_date; private javax.swing.JButton newBtn; private javax.swing.JButton printBtn; private javax.swing.JButton saveBtn; private javax.swing.JTextField txt_age; private javax.swing.JTextField txt_attachImg_path; private javax.swing.JTextField txt_empID; private javax.swing.JTextField txt_firstName; private javax.swing.JTextField txt_lastName; private javax.swing.JTextField txt_search; // End of variables declaration//GEN-END:variables Timer timer; private ImageIcon format = null; String filename = null; int s = 0; byte[] person_image = null; private String gender; }