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 employeepayroll; import com.itextpdf.text.BaseColor; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Dimension; import java.awt.Toolkit; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font.FontFamily; import com.itextpdf.text.FontFactory; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.GrayColor; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.PdfPTable; import java.awt.Font; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import java.util.Date; import java.util.GregorianCalendar; /** * * @author makh */ public class mainMenu extends javax.swing.JFrame { Connection conn = null; ResultSet rs = null; PreparedStatement pst = null; /** * Creates new form mainMenu */ public mainMenu() { initComponents(); centerWindow(); lbl_empname.setText(String.valueOf(EmployeeDetails.emp_name).toString()); } public final void centerWindow() { conn = db.java_db(); Toolkit toolkit = getToolkit(); Dimension size = toolkit.getScreenSize(); setLocation(size.width / 2 - getWidth() / 2, size.height / 2 - getHeight() / 2); //txt_emp.setText(String.valueOf(Emp.empId).toString()); } /** * 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(); jButton1 = new javax.swing.JButton(); lbl_empname = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem7 = new javax.swing.JMenuItem(); emp_rp = new javax.swing.JMenu(); emp_ta_rp = new javax.swing.JMenuItem(); emp_td_rp = new javax.swing.JMenuItem(); jMenuItem3 = new javax.swing.JMenuItem(); jMenuItem1 = new javax.swing.JMenuItem(); jMenu4 = new javax.swing.JMenu(); jMenuItem4 = new javax.swing.JMenuItem(); jMenuItem6 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem5 = new javax.swing.JMenuItem(); jMenu5 = new javax.swing.JMenu(); jMenu3 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jPanel1.setLayout(null); jButton1.setFont(new java.awt.Font("Trebuchet MS", 1, 18)); // NOI18N jButton1.setIcon( new javax.swing.ImageIcon(getClass().getResource("/employeepayroll/images/icons/logout.png"))); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jPanel1.add(jButton1); jButton1.setBounds(920, 30, 55, 32); lbl_empname.setForeground(new java.awt.Color(226, 197, 197)); lbl_empname.setText("emp_name"); jPanel1.add(lbl_empname); lbl_empname.setBounds(190, 580, 77, 17); jLabel1.setForeground(new java.awt.Color(226, 197, 197)); jLabel1.setText("You are Logged in as: "); jPanel1.add(jLabel1); jLabel1.setBounds(20, 580, 149, 17); jButton2.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N jButton2.setIcon(new javax.swing.ImageIcon( getClass().getResource("/employeepayroll/images/icons/Add_Employee.png"))); // NOI18N jButton2.setText("Employee Management"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jPanel1.add(jButton2); jButton2.setBounds(720, 420, 260, 60); jButton3.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N jButton3.setIcon( new javax.swing.ImageIcon(getClass().getResource("/employeepayroll/images/icons/Allowance.png"))); // NOI18N jButton3.setText("Allowances"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jPanel1.add(jButton3); jButton3.setBounds(470, 490, 240, 60); jButton4.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N jButton4.setIcon( new javax.swing.ImageIcon(getClass().getResource("/employeepayroll/images/icons/Update.png"))); // NOI18N jButton4.setText("Update Salaries"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jPanel1.add(jButton4); jButton4.setBounds(720, 490, 260, 62); jButton5.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N jButton5.setIcon( new javax.swing.ImageIcon(getClass().getResource("/employeepayroll/images/icons/Payment.png"))); // NOI18N jButton5.setText("Payments"); jPanel1.add(jButton5); jButton5.setBounds(720, 560, 260, 60); jButton7.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N jButton7.setIcon( new javax.swing.ImageIcon(getClass().getResource("/employeepayroll/images/icons/Deduction.png"))); // NOI18N jButton7.setText("Deductions"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); jPanel1.add(jButton7); jButton7.setBounds(470, 560, 240, 62); jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employeepayroll/images/icons/bk2.jpg"))); // NOI18N jPanel1.add(jLabel2); jLabel2.setBounds(0, -20, 1000, 700); jMenu1.setText("File"); jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK)); jMenuItem7.setText("Exit"); jMenuItem7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem7ActionPerformed(evt); } }); jMenu1.add(jMenuItem7); jMenuBar1.add(jMenu1); emp_rp.setText("Reports"); emp_ta_rp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK)); emp_ta_rp.setText("Employee List RP"); emp_ta_rp.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { emp_ta_rpActionPerformed(evt); } }); emp_rp.add(emp_ta_rp); emp_td_rp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK)); emp_td_rp.setText("Employee Total Allowances RP"); emp_td_rp.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { emp_td_rpActionPerformed(evt); } }); emp_rp.add(emp_td_rp); jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem3.setText("Employee Total Deductions RP"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); emp_rp.add(jMenuItem3); jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem1.setText("Retirement List RP"); emp_rp.add(jMenuItem1); jMenuBar1.add(emp_rp); jMenu4.setText("Employee"); jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem4.setText("Add Employee"); jMenuItem4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem4ActionPerformed(evt); } }); jMenu4.add(jMenuItem4); jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem6.setText("Performance Evaluation"); jMenu4.add(jMenuItem6); jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem2.setText("Generate Slips"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu4.add(jMenuItem2); jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem5.setText("Audit Trail"); jMenu4.add(jMenuItem5); jMenuBar1.add(jMenu4); jMenu5.setText("Help"); jMenuBar1.add(jMenu5); jMenu3.setText("About"); 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) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1000, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 641, javax.swing.GroupLayout.PREFERRED_SIZE)); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: Login x = new Login(); x.setVisible(true); this.dispose(); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: AddEmployee emp_add = new AddEmployee(); emp_add.setVisible(true); //this.dispose(); }//GEN-LAST:event_jButton2ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: Allowance emp_all = new Allowance(); emp_all.setVisible(true); //this.dispose(); }//GEN-LAST:event_jButton3ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: UpdateSalary sal = new UpdateSalary(); sal.setVisible(true); //this.dispose(); }//GEN-LAST:event_jButton4ActionPerformed private void emp_td_rpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emp_td_rpActionPerformed // TODO add your handling code here: JFileChooser dialog = new JFileChooser(); dialog.setSelectedFile(new File("Employee Allowance Report.pdf")); int dialogResult = dialog.showSaveDialog(null); if (dialogResult == JFileChooser.APPROVE_OPTION) { String filePath = dialog.getSelectedFile().getPath(); try { String sql = "select * from Allowance"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); Document myDocument = new Document(); PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath)); PdfPTable table = new PdfPTable(11); myDocument.open(); float[] columnWidths = new float[] { 3, 7, 7, 5, 5, 9, 6, 5, 8, 8, 8 }; table.setWidths(columnWidths); table.setWidthPercentage(100); //set table width to 100% myDocument.add(new Paragraph("Employees Allowance List", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD))); myDocument.add(new Paragraph(new Date().toString())); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); table.addCell(new PdfPCell( new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Overtime", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Medical", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Bonus", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Other", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Employee ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Rate", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Allowance", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); while (rs.next()) { table.addCell(new PdfPCell(new Paragraph(rs.getString(1), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(2), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(3), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(4), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(5), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(6), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(7), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(8), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(9), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(10), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(11), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); } myDocument.add(table); myDocument.add(new Paragraph( "--------------------------------------------------------------------------------------------")); myDocument.close(); JOptionPane.showMessageDialog(null, "Allowance Report was successfully generated"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { rs.close(); pst.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } }//GEN-LAST:event_emp_td_rpActionPerformed private void emp_ta_rpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emp_ta_rpActionPerformed // TODO add your handling code here: JFileChooser dialog = new JFileChooser(); dialog.setSelectedFile(new File("Employees Report.pdf")); int dialogResult = dialog.showSaveDialog(null); if (dialogResult == JFileChooser.APPROVE_OPTION) { String filePath = dialog.getSelectedFile().getPath(); try { String sql = "select * from emp_info"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); Document myDocument = new Document(); PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath)); PdfPTable table = new PdfPTable(13); myDocument.open(); float[] columnWidths = new float[] { 3, 8, 7, 5, 5, 9, 8, 9, 6, 6, 6, 8, 8 }; table.setWidths(columnWidths); table.setWidthPercentage(100); //set table width to 100% myDocument.add(new Paragraph("Employees List", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD))); myDocument.add(new Paragraph(new Date().toString())); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); table.addCell(new PdfPCell( new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell(new Paragraph("Date of Birth", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Email", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Telephone", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Address", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Department", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Gender", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Status", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Date Hired", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Job Title", FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD)))); while (rs.next()) { table.addCell(new PdfPCell(new Paragraph(rs.getString(1), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(2), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(3), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(4), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(5), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(6), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(7), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(8), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(10), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(11), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(16), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(17), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(18), FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.PLAIN)))); } myDocument.add(table); myDocument.add(new Paragraph( "--------------------------------------------------------------------------------------------")); myDocument.close(); JOptionPane.showMessageDialog(null, "Report was successfully generated"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { rs.close(); pst.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } }//GEN-LAST:event_emp_ta_rpActionPerformed private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed // TODO add your handling code here: Deduction empdeduct = new Deduction(); empdeduct.setVisible(true); }//GEN-LAST:event_jButton7ActionPerformed private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed // TODO add your handling code here: AddEmployee emp_add = new AddEmployee(); emp_add.setVisible(true); }//GEN-LAST:event_jMenuItem4ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed // TODO add your handling code here: Searchempsalary emp_rp = new Searchempsalary(); emp_rp.setVisible(true); }//GEN-LAST:event_jMenuItem2ActionPerformed private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed // TODO add your handling code here: this.dispose(); }//GEN-LAST:event_jMenuItem7ActionPerformed private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed // TODO add your handling code here: JFileChooser dialog = new JFileChooser(); dialog.setSelectedFile(new File("Employee Deduction Report.pdf")); int dialogResult = dialog.showSaveDialog(null); if (dialogResult == JFileChooser.APPROVE_OPTION) { String filePath = dialog.getSelectedFile().getPath(); try { String sql = "select * from Deductions"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); Document myDocument = new Document(); PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath)); PdfPTable table = new PdfPTable(8); myDocument.open(); float[] columnWidths = new float[] { 3, 7, 7, 5, 5, 9, 6, 5 }; table.setWidths(columnWidths); table.setWidthPercentage(100); //set table width to 100% myDocument.add(new Paragraph("Employees Deduction List", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD))); myDocument.add(new Paragraph(new Date().toString())); myDocument.add(new Paragraph( "-------------------------------------------------------------------------------------------")); table.addCell(new PdfPCell( new Paragraph("ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Surname", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Salary", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell(new Paragraph("Deduction Amount", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell(new Paragraph("Deduction Reason", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Employee ID", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); table.addCell(new PdfPCell( new Paragraph("Created By", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD)))); while (rs.next()) { table.addCell(new PdfPCell(new Paragraph(rs.getString(1), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(2), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(3), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(4), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(5), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(6), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(7), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); table.addCell(new PdfPCell(new Paragraph(rs.getString(8), FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.PLAIN)))); } myDocument.add(table); myDocument.add(new Paragraph( "--------------------------------------------------------------------------------------------")); myDocument.close(); JOptionPane.showMessageDialog(null, "Deductions Report was successfully generated"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { rs.close(); pst.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } }//GEN-LAST:event_jMenuItem3ActionPerformed /** * @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(mainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(mainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(mainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(mainMenu.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 mainMenu().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenu emp_rp; private javax.swing.JMenuItem emp_ta_rp; private javax.swing.JMenuItem emp_td_rp; 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 jButton7; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu3; private javax.swing.JMenu jMenu4; private javax.swing.JMenu jMenu5; 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.JMenuItem jMenuItem5; private javax.swing.JMenuItem jMenuItem6; private javax.swing.JMenuItem jMenuItem7; private javax.swing.JPanel jPanel1; private javax.swing.JLabel lbl_empname; // End of variables declaration//GEN-END:variables }