Account.java Source code

Java tutorial

Introduction

Here is the source code for Account.java

Source

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
//import javax.swing.table.TableModel;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import jxl.*;
import jxl.read.biff.BiffException;
/*
 * 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 ARPITA  AYUSHI
 */
public class Account extends javax.swing.JFrame {

    /**
     * Creates new form Account
     */
    public Account() {
        super("Accounting Soft by Arpita Jaiswal");
        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() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jPanel5 = new javax.swing.JPanel();
        jTextField14 = new javax.swing.JTextField();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jTextField15 = new javax.swing.JTextField();
        jTextField16 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jTextField9 = new javax.swing.JTextField();
        jTextField10 = new javax.swing.JTextField();
        jTextField11 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jTextField12 = new javax.swing.JTextField();
        jTextField13 = new javax.swing.JTextField();
        jButton9 = new javax.swing.JButton();
        jTextField17 = new javax.swing.JTextField();
        jTextField18 = new javax.swing.JTextField();
        jTextField19 = new javax.swing.JTextField();
        jTextField20 = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel5.setVisible(false);
        jPanel5.setOpaque(false);

        jTextField14.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N
        jTextField14.setText("Payment");
        jTextField14.setToolTipText("");
        jTextField14.setOpaque(false);
        jTextField14.setEditable(false);
        jTextField14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField14ActionPerformed(evt);
            }
        });

        jButton11.setText("Replacement");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.setText("Payments");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jButton13.setText("Delete the selected entry");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jButton14.setText("Main");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jTable3.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { { null, new Integer(0) } },
                new String[] { "Date", "Payments" }) {
            Class[] types = new Class[] { java.lang.Object.class, java.lang.Integer.class };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }
        });
        jTable3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable3KeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(jTable3);

        jTextField15.setEditable(false);
        jTextField15.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField15.setText("Payment Total");
        jTextField15.setOpaque(false);
        jTextField15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField15ActionPerformed(evt);
            }
        });

        jTextField16.setEditable(false);
        jTextField16.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField16.setText("0");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(jPanel5Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup().addGap(93, 93, 93)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel5Layout.createSequentialGroup()
                                        .addComponent(jTextField15, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField16, javax.swing.GroupLayout.PREFERRED_SIZE, 125,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jScrollPane3).addComponent(jTextField14,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
                        .addGroup(
                                jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 184,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 184,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(174, 174, 174)));
        jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup().addGap(52, 52, 52)
                        .addComponent(jTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, 45,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel5Layout.createSequentialGroup().addComponent(jButton14)
                                        .addGap(18, 18, 18).addComponent(jButton11).addGap(18, 18, 18)
                                        .addComponent(jButton12).addGap(18, 18, 18).addComponent(jButton13))
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 320,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jTextField15, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextField16, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(149, Short.MAX_VALUE)));

        jPanel4.setVisible(false);
        jPanel4.setOpaque(false);

        jTextField9.setEditable(false);
        jTextField9.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField9.setText("Replacement Total");
        jTextField9.setOpaque(false);
        jTextField9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField9ActionPerformed(evt);
            }
        });

        jTextField10.setEditable(false);
        jTextField10.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField10.setText("0");

        jTextField11.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N
        jTextField11.setText("Replacement");
        jTextField11.setToolTipText("");
        jTextField11.setOpaque(false);
        jTextField11.setEditable(false);
        jTextField11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField11ActionPerformed(evt);
            }
        });

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, new Integer(0), new Integer(0), null } },
                new String[] { "Date", "Goods", "Quantity", "Rate", "Total" }) {
            Class[] types = new Class[] { java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class,
                    java.lang.Integer.class, java.lang.Long.class };
            boolean[] canEdit = new boolean[] { true, true, true, true, false };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jTable2.setOpaque(false);
        jTable2.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                jTable2CaretPositionChanged(evt);
            }

            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTable2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable2KeyPressed(evt);
            }

            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTable2KeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jButton6.setText("Main");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Replacement");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Payments");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton10.setText("Delete the selected entry");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup().addGap(89, 89, 89).addGroup(jPanel4Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 497,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(75, 75, 75)
                                        .addGroup(jPanel4Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 184,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, 497,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel4Layout.createSequentialGroup().addGap(320, 320, 320)
                                .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 125,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(139, Short.MAX_VALUE)));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addGap(50, 50, 50)
                        .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, 45,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 322,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel4Layout.createSequentialGroup().addComponent(jButton6)
                                        .addGap(18, 18, 18).addComponent(jButton7).addGap(18, 18, 18)
                                        .addComponent(jButton8).addGap(18, 18, 18).addComponent(jButton10)))
                        .addGap(18, 18, 18)
                        .addGroup(
                                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel4Layout.createSequentialGroup().addComponent(jTextField10)
                                                .addGap(2, 2, 2)))
                        .addContainerGap(149, Short.MAX_VALUE)));

        jPanel3.setOpaque(false);
        jPanel3.setVisible(false);

        jLabel2.setBackground(new java.awt.Color(255, 153, 255));
        jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
        jLabel2.setText("Type the Title name");

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(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().addGap(292, 292, 292)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 260,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 247,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(jPanel3Layout.createSequentialGroup().addGap(83, 83, 83)
                                                        .addComponent(jButton1))))
                        .addContainerGap(465, Short.MAX_VALUE)));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addGap(209, 209, 209)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 44,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 40,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27).addComponent(jButton1).addContainerGap(296, Short.MAX_VALUE)));

        jPanel2.setOpaque(false);
        jPanel2.setVisible(false);

        jTextField1.setFont(new java.awt.Font("Comic Sans MS", 0, 24)); // NOI18N
        jTextField1.setToolTipText("");
        jTextField1.setOpaque(false);
        jTextField1.setText(jTextField2.getText());
        jTextField1.setEditable(false);
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, new Integer(0), new Integer(0), null } },
                new String[] { "Date", "Goods", "Quantity", "Rate", "Total" }) {
            Class[] types = new Class[] { java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class,
                    java.lang.Integer.class, java.lang.Long.class };
            boolean[] canEdit = new boolean[] { true, true, true, true, false };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jTable1.setOpaque(false);
        jTable1.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                jTable1CaretPositionChanged(evt);
            }

            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }

            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTable1KeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTextField3.setEditable(false);
        jTextField3.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField3.setText("Grand Total");
        jTextField3.setOpaque(false);

        jTextField4.setEditable(false);
        jTextField4.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField4.setText("0");

        jTextField5.setEditable(false);
        jTextField5.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField5.setText("Last Figure");

        jTextField6.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField6.setText("0");

        jButton2.setText("OK");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField7.setEditable(false);
        jTextField7.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField7.setText("Total + last figure");

        jTextField8.setEditable(false);
        jTextField8.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField8.setText("0");

        jButton3.setText("Main");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Replacement");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Payments");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jTextField12.setEditable(false);
        jTextField12.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField12.setText("Total-replacement+Figure");
        jTextField12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField12ActionPerformed(evt);
            }
        });

        jTextField13.setEditable(false);
        jTextField13.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField13.setText("0");
        jTextField13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField13ActionPerformed(evt);
            }
        });

        jButton9.setText("Delete the selected entry");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jTextField17.setEditable(false);
        jTextField17.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField17.setText("Payment Total");

        jTextField18.setEditable(false);
        jTextField18.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField18.setText("0");

        jTextField19.setEditable(false);
        jTextField19.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTextField19.setText("New Grand Total");
        jTextField19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField19ActionPerformed(evt);
            }
        });

        jTextField20.setEditable(false);
        jTextField20.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField20.setText("0");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(94, 94, 94).addGroup(jPanel2Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jTextField19, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField20, javax.swing.GroupLayout.PREFERRED_SIZE, 89,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextField17, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField18, javax.swing.GroupLayout.DEFAULT_SIZE, 97,
                                                Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        497, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        497, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(jPanel2Layout.createSequentialGroup()
                                                        .addComponent(jTextField5,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jTextField6,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 94,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(jButton2,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 60,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jTextField7,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(jPanel2Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(jTextField8,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE, 97,
                                                                Short.MAX_VALUE)
                                                        .addComponent(jTextField4))))
                                .addGap(70, 70, 70)
                                .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(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 184,
                                                Short.MAX_VALUE)
                                        .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addContainerGap(171, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(47, 47, 47)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 45,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(44, 44, 44)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 322,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jButton3)
                                        .addGap(18, 18, 18).addComponent(jButton4).addGap(18, 18, 18)
                                        .addComponent(jButton5).addGap(19, 19, 19).addComponent(jButton9)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 26,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(
                                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jTextField17, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        27, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jTextField12, javax.swing.GroupLayout.DEFAULT_SIZE, 29,
                                                Short.MAX_VALUE)
                                        .addComponent(jTextField13, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jTextField19, javax.swing.GroupLayout.DEFAULT_SIZE, 29,
                                                Short.MAX_VALUE)
                                        .addGap(43, 43, 43))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jTextField20, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/note2.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING));

        javax.swing.GroupLayout jLayeredPane1Layout = new javax.swing.GroupLayout(jLayeredPane1);
        jLayeredPane1.setLayout(jLayeredPane1Layout);
        jLayeredPane1Layout.setHorizontalGroup(jLayeredPane1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jLayeredPane1Layout.createSequentialGroup()
                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jLayeredPane1Layout
                .setVerticalGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jLayeredPane1.setLayer(jPanel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jPanel4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jPanel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jPanel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N,
                java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/notebook2.jpg"))); // NOI18N
        jMenuItem1.setText("New");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
                java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/open1.png"))); // NOI18N
        jMenuItem3.setText("Open");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X,
                java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Excel1.png"))); // NOI18N
        jMenuItem2.setText("Export to Excel");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLayeredPane1));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLayeredPane1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        jPanel3.setVisible(true);
        jPanel2.setVisible(false);
        jPanel4.setVisible(false);
        jPanel5.setVisible(false);

    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        jPanel2.setVisible(true);
        jPanel3.setVisible(false);
        jTextField1.setText(jTextField2.getText());
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        int n = model.getRowCount();
        //int index = jTable1.getSelectedRow();
        //System.out.println(n+"thr "+index);
        for (int i = n - 1; i >= 0; i--)
            model.removeRow(i);
        Object[] row = { null, null, 0, 0, 0 };
        model.addRow(row);
        DefaultTableModel model1 = (DefaultTableModel) jTable2.getModel();
        n = model1.getRowCount();

        for (int i = n - 1; i >= 0; i--)
            model1.removeRow(i);
        Object[] row1 = { null, null, 0, 0, 0 };
        model1.addRow(row1);
        DefaultTableModel model2 = (DefaultTableModel) jTable3.getModel();
        n = model2.getRowCount();

        for (int i = n - 1; i >= 0; i--)
            model2.removeRow(i);
        Object[] row2 = { null, 0 };
        model2.addRow(row2);
        jTextField4.setText("0");
        jTextField6.setText("0");
        jTextField8.setText("0");
        jTextField13.setText("0");
        jTextField10.setText("0");
        jTextField18.setText("0");
        jTextField20.setText("0");
        jTextField16.setText("0");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        //jTextField1.setText(jTextField2.getText());
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
        int index = jTable1.getSelectedRow();
        //System.out.println(index);
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        int no, number = model.getRowCount();
        no = number;
        if (model.getValueAt(index, 1) != null) {

            int quantity = Integer.parseInt(model.getValueAt(index, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(index, 3).toString());
            Object[] row = { null, null, 0, 0, 0 };
            long total = quantity * rate;
            model.setValueAt(total, index, 4);

            System.out.println(model.getValueAt(number - 1, 1));
            if (model.getValueAt(number - 1, 1) != null)
                model.addRow(row);
            else
                number--;
            long total1 = 0;
            for (int i = 0; i < number; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 4).toString());
            }
            //System.out.println(total1);
            jTextField4.setText(Long.toString(total1));
        }
        if (model.getValueAt(no - 1, 1) == null)
            no--;
        for (int j = 0; j < no; j++) {
            int quantity = Integer.parseInt(model.getValueAt(j, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(j, 3).toString());
            //Object[] row = {null,null,0,0,0};
            long total = quantity * rate;
            model.setValueAt(total, j, 4);
        }
        long total1 = 0;
        for (int i = 0; i < no; i++) {
            total1 = total1 + Integer.parseInt(model.getValueAt(i, 4).toString());
        }
        //System.out.println(total1);
        jTextField4.setText(Long.toString(total1));
        Long t, result = Long.parseLong(jTextField6.getText()) + Long.parseLong(jTextField4.getText());
        jTextField8.setText(Long.toString(result));
        t = result - Long.parseLong(jTextField10.getText());
        jTextField13.setText(Long.toString(t));
        jTextField18.setText(jTextField16.getText());
        t = t - Long.parseLong(jTextField16.getText());
        jTextField20.setText(Long.toString(t));
    }//GEN-LAST:event_jTable1KeyPressed

    public void refresh() {
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        int no = model.getRowCount();
        if (model.getValueAt(no - 1, 1) == null)
            no--;
        for (int j = 0; j < no; j++) {
            int quantity = Integer.parseInt(model.getValueAt(j, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(j, 3).toString());
            Object[] row = { null, null, 0, 0, 0 };
            long total = quantity * rate;
            model.setValueAt(total, j, 4);
            long total1 = 0;
            for (int i = 0; i < no; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 4).toString());
            }
            //System.out.println(total1);
            jTextField4.setText(Long.toString(total1));
        }
        long result = Long.parseLong(jTextField6.getText()) + Long.parseLong(jTextField4.getText());
        jTextField8.setText(Long.toString(result));
        result = result - Long.parseLong(jTextField10.getText());
        jTextField13.setText(Long.toString(result));
        jTextField18.setText(jTextField16.getText());
        result = result - Long.parseLong(jTextField16.getText());
        jTextField20.setText(Long.toString(result));
        DefaultTableModel model1 = (DefaultTableModel) jTable2.getModel();
        int no1 = model1.getRowCount();
        if (model1.getValueAt(no1 - 1, 1) == null)
            no1--;
        for (int j = 0; j < no1; j++) {
            int quantity = Integer.parseInt(model1.getValueAt(j, 2).toString());
            int rate = Integer.parseInt(model1.getValueAt(j, 3).toString());
            Object[] row = { null, null, 0, 0, 0 };
            long total = quantity * rate;
            model1.setValueAt(total, j, 4);
            long total1 = 0;
            for (int i = 0; i < no1; i++) {
                total1 = total1 + Integer.parseInt(model1.getValueAt(i, 4).toString());
            }
            //System.out.println(total1);
            jTextField10.setText(Long.toString(total1));
        }
        model = (DefaultTableModel) jTable3.getModel();
        no = model.getRowCount();
        if (model.getValueAt(no - 1, 0) == null)
            no--;
        for (int j = 0; j < no; j++) {
            /* int quantity = Integer.parseInt(model.getValueAt(j, 2).toString());
             int rate = Integer.parseInt(model.getValueAt(j, 3).toString());
             Object[] row = {null,null,0,0,0};
             long total = quantity * rate;
             model.setValueAt(total, j, 4);*/
            long total1 = 0;
            for (int i = 0; i < no; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 1).toString());
            }
            //System.out.println(total1);
            jTextField16.setText(Long.toString(total1));
        }

    }

    private void selection() {
        chooser = new JFileChooser();
        //chooser.setCurrentDirectory(new java.io.File("."));
        chooser.setDialogTitle(choosertitle);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.showSaveDialog(jMenuItem2);
        //
        // disable the "All files" option.
        //
        /* chooser.setAcceptAllFileFilterUsed(false);
         //    
         if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 
           System.out.println("getCurrentDirectory(): " 
              +  chooser.getCurrentDirectory());
           System.out.println("getSelectedFile() : " 
              +  chooser.getSelectedFile());
           }
         else {
           System.out.println("No Selection ");
           }*/
    }

    public void writetoexcel() throws FileNotFoundException, IOException {
        refresh();
        selection();
        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        DefaultTableModel dt = (DefaultTableModel) jTable2.getModel();
        DefaultTableModel d = (DefaultTableModel) jTable3.getModel();
        Workbook wb = new HSSFWorkbook();
        //XSSFWorkbook wb = new XSSFWorkbook();
        CreationHelper createhelper = wb.getCreationHelper();
        Sheet sheet = wb.createSheet("new sheet");
        Row row = null;
        Cell cell = null;
        row = sheet.createRow(0);
        cell = row.createCell(0);
        cell.setCellValue(jTextField1.getText());
        cell = row.createCell(6);
        cell.setCellValue("Replacement");

        row = sheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("Date");
        cell = row.createCell(6);
        cell.setCellValue("Date");

        cell = row.createCell(1);
        cell.setCellValue("Goods");
        cell = row.createCell(2);
        cell.setCellValue("Quantity");
        cell = row.createCell(3);
        cell.setCellValue("Rate");
        cell = row.createCell(4);
        cell.setCellValue("Total");

        cell = row.createCell(7);
        cell.setCellValue("Goods");
        cell = row.createCell(8);
        cell.setCellValue("Quantity");
        cell = row.createCell(9);
        cell.setCellValue("Rate");
        cell = row.createCell(10);
        cell.setCellValue("Total");

        int t = dtm.getRowCount();
        int m = dt.getRowCount();
        int y = d.getRowCount();
        int i, z;
        if (dtm.getValueAt(t - 1, 1) != null)
            t++;
        if (dt.getValueAt(m - 1, 1) != null)
            m++;
        if (d.getValueAt(y - 1, 0) != null)
            y++;
        if (t < m) {
            z = m;
            for (i = 0; i < t - 1; i++) {
                row = sheet.createRow(i + 2);
                for (int j = 0; j < dtm.getColumnCount(); j++) {

                    cell = row.createCell(j);
                    if (j == 4)
                        cell.setCellValue((Long) dtm.getValueAt(i, j));
                    else if (j == 0 || j == 1)
                        cell.setCellValue((String) dtm.getValueAt(i, j));
                    else
                        cell.setCellValue((Integer) dtm.getValueAt(i, j));

                    cell = row.createCell(j + 6);
                    if (j == 4)
                        cell.setCellValue((Long) dt.getValueAt(i, j));
                    else if (j == 0 || j == 1)
                        cell.setCellValue((String) dt.getValueAt(i, j));
                    else
                        cell.setCellValue(Integer.parseInt(dt.getValueAt(i, j).toString()));
                }
            }
            //i--;
            row = sheet.createRow(t + 2);
            cell = row.createCell(2);
            cell.setCellValue(jTextField3.getText());
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField4.getText()));

            row = sheet.createRow(t + 3);
            cell = row.createCell(2);
            cell.setCellValue(jTextField5.getText());
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField6.getText()));

            row = sheet.createRow(t + 4);
            cell = row.createCell(2);
            cell.setCellValue(jTextField7.getText());
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField8.getText()));

            row = sheet.createRow(t + 5);
            cell = row.createCell(2);
            cell.setCellValue("Total Replacement");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField10.getText()));

            row = sheet.createRow(t + 6);
            cell = row.createCell(2);
            cell.setCellValue("Total");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField13.getText()));

            row = sheet.createRow(t + 7);
            cell = row.createCell(2);
            cell.setCellValue("Payment Total");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField16.getText()));

            row = sheet.createRow(t + 8);
            cell = row.createCell(2);
            cell.setCellValue("New Grand Total");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField20.getText()));

            int k = i;
            while (i <= m - 1) {
                row = sheet.createRow(i + 2);
                if (i == k + 1) {
                    cell = row.createCell(2);
                    cell.setCellValue(jTextField3.getText());
                    cell = row.createCell(4);
                    cell.setCellValue(Long.parseLong(jTextField4.getText()));
                }

                if (i == k + 2) {
                    cell = row.createCell(2);
                    cell.setCellValue(jTextField5.getText());
                    cell = row.createCell(4);
                    cell.setCellValue(Long.parseLong(jTextField6.getText()));

                }

                if (i == k + 3) {
                    cell = row.createCell(2);
                    cell.setCellValue(jTextField7.getText());
                    cell = row.createCell(4);
                    cell.setCellValue(Long.parseLong(jTextField8.getText()));
                }

                if (i == k + 4) {
                    cell = row.createCell(2);
                    cell.setCellValue("Total Replacement");
                    cell = row.createCell(4);
                    cell.setCellValue(Long.parseLong(jTextField10.getText()));
                }

                if (i == k + 5) {
                    cell = row.createCell(2);
                    cell.setCellValue("Total");
                    cell = row.createCell(4);
                    cell.setCellValue(Long.parseLong(jTextField13.getText()));
                }

                if (i == k + 6) {
                    cell = row.createCell(2);
                    cell.setCellValue("Payment Total");
                    cell = row.createCell(4);
                    cell.setCellValue(Long.parseLong(jTextField16.getText()));
                }
                if (i == k + 7) {
                    cell = row.createCell(2);
                    cell.setCellValue("New Grand Total");
                    cell = row.createCell(4);
                    cell.setCellValue(Long.parseLong(jTextField20.getText()));
                }
                if (i == m - 1) {
                    cell = row.createCell(8);
                    cell.setCellValue("Total Replacement");
                    cell = row.createCell(10);
                    cell.setCellValue(Long.parseLong(jTextField10.getText()));
                } else {
                    for (int j = 0; j < dtm.getColumnCount(); j++) {

                        cell = row.createCell(j + 6);
                        if (j == 4)
                            cell.setCellValue((Long) dt.getValueAt(i, j));
                        else if (j == 0 || j == 1)
                            cell.setCellValue((String) dt.getValueAt(i, j));
                        else
                            cell.setCellValue(Integer.parseInt(dt.getValueAt(i, j).toString()));
                    }
                }
                i++;
            }
            row = sheet.createRow(m + 9);
            cell = row.createCell(0);
            cell.setCellValue("Payment");
            row = sheet.createRow(m + 10);
            cell = row.createCell(0);
            cell.setCellValue("Date");
            cell = row.createCell(1);
            cell.setCellValue("Payments");
            for (int u = 0; u < y - 1; u++) {
                row = sheet.createRow(u + m + 11);
                for (int j = 0; j < d.getColumnCount(); j++) {

                    cell = row.createCell(j);
                    if (j == 0)
                        cell.setCellValue((String) d.getValueAt(u, j));
                    else
                        cell.setCellValue(Integer.parseInt(d.getValueAt(u, j).toString()));
                }
            }
            row = sheet.createRow(m + 11 + y);
            cell = row.createCell(0);
            cell.setCellValue("Payment Total");
            cell = row.createCell(1);
            cell.setCellValue(Long.parseLong(jTextField16.getText()));
        } else {
            for (i = 0; i < m - 1; i++) {
                row = sheet.createRow(i + 2);
                for (int j = 0; j < dtm.getColumnCount(); j++) {

                    cell = row.createCell(j);
                    if (j == 4)
                        cell.setCellValue((Long) dtm.getValueAt(i, j));
                    else if (j == 0 || j == 1)
                        cell.setCellValue((String) dtm.getValueAt(i, j));
                    else
                        cell.setCellValue((Integer) dtm.getValueAt(i, j));

                    cell = row.createCell(j + 6);
                    if (j == 4)
                        cell.setCellValue((Long) dt.getValueAt(i, j));
                    else if (j == 0 || j == 1)
                        cell.setCellValue((String) dt.getValueAt(i, j));
                    else
                        cell.setCellValue(Integer.parseInt(dt.getValueAt(i, j).toString()));
                }
            }
            //i--;
            int k = i;
            while (i <= t - 1) {
                row = sheet.createRow(i + 2);
                if (i == k) {
                    cell = row.createCell(8);
                    cell.setCellValue("Total Replacement");
                    cell = row.createCell(10);
                    cell.setCellValue(Long.parseLong(jTextField10.getText()));
                }
                if (i != t - 1) {
                    for (int j = 0; j < dtm.getColumnCount(); j++) {

                        cell = row.createCell(j);
                        if (j == 4)
                            cell.setCellValue((Long) dtm.getValueAt(i, j));
                        else if (j == 0 || j == 1)
                            cell.setCellValue((String) dtm.getValueAt(i, j));
                        else
                            cell.setCellValue((Integer) dtm.getValueAt(i, j));
                    }
                }
                i++;
            }
            row = sheet.createRow(t + 2);
            cell = row.createCell(2);
            cell.setCellValue(jTextField3.getText());
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField4.getText()));

            row = sheet.createRow(t + 3);
            cell = row.createCell(2);
            cell.setCellValue(jTextField5.getText());
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField6.getText()));

            row = sheet.createRow(t + 4);
            cell = row.createCell(2);
            cell.setCellValue(jTextField7.getText());
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField8.getText()));

            row = sheet.createRow(t + 5);
            cell = row.createCell(2);
            cell.setCellValue("Total Replacement");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField10.getText()));

            row = sheet.createRow(t + 6);
            cell = row.createCell(2);
            cell.setCellValue("Total");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField13.getText()));

            row = sheet.createRow(t + 7);
            cell = row.createCell(2);
            cell.setCellValue("Payment Total");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField16.getText()));

            row = sheet.createRow(t + 8);
            cell = row.createCell(2);
            cell.setCellValue("New Grand Total");
            cell = row.createCell(4);
            cell.setCellValue(Long.parseLong(jTextField20.getText()));

            row = sheet.createRow(t + 10);
            cell = row.createCell(0);
            cell.setCellValue("Payment");
            row = sheet.createRow(t + 11);
            cell = row.createCell(0);
            cell.setCellValue("Date");
            cell = row.createCell(1);
            cell.setCellValue("Payments");
            for (int u = 0; u < y - 1; u++) {
                row = sheet.createRow(u + t + 12);
                for (int j = 0; j < d.getColumnCount(); j++) {

                    cell = row.createCell(j);
                    if (j == 0)
                        cell.setCellValue((String) d.getValueAt(u, j));
                    else
                        cell.setCellValue(Integer.parseInt(d.getValueAt(u, j).toString()));
                }
            }
            row = sheet.createRow(t + y + 12);
            cell = row.createCell(0);
            cell.setCellValue("Payment Total");
            cell = row.createCell(1);
            cell.setCellValue(Long.parseLong(jTextField16.getText()));
        }

        FileOutputStream out = new FileOutputStream(
                chooser.getSelectedFile() + "\\" + jTextField1.getText() + ".xls");
        wb.write(out);
        out.close();
    }

    public void writereplacement() throws FileNotFoundException, IOException {
        DefaultTableModel dtm = (DefaultTableModel) jTable2.getModel();
        Workbook wb = new HSSFWorkbook();
        //XSSFWorkbook wb = new XSSFWorkbook();
        CreationHelper createhelper = wb.getCreationHelper();
        Sheet sheet = wb.createSheet("new sheet");
        Row row = null;
        Cell cell = null;
        row = sheet.createRow(0);
        cell = row.createCell(6);
        cell.setCellValue("Replacement");
        row = sheet.createRow(1);
        cell = row.createCell(6);
        cell.setCellValue("Date");
        cell = row.createCell(7);
        cell.setCellValue("Goods");
        cell = row.createCell(8);
        cell.setCellValue("Quantity");
        cell = row.createCell(9);
        cell.setCellValue("Rate");
        cell = row.createCell(10);
        cell.setCellValue("Total");
        int t = dtm.getRowCount();
        if (dtm.getValueAt(t - 1, 1) != null)
            t++;
        for (int i = 0; i < t - 1; i++) {
            row = sheet.createRow(i + 2);
            for (int j = 0; j < dtm.getColumnCount(); j++) {

                cell = row.createCell(j + 6);
                if (j == 4)
                    cell.setCellValue((Long) dtm.getValueAt(i, j));
                else if (j == 0 || j == 1)
                    cell.setCellValue((String) dtm.getValueAt(i, j));
                else
                    cell.setCellValue((Integer) dtm.getValueAt(i, j));
            }
        }

        row = sheet.createRow(t + 2);
        cell = row.createCell(2 + 6);
        cell.setCellValue("Replacement Total");
        cell = row.createCell(4 + 6);
        cell.setCellValue(Long.parseLong(jTextField10.getText()));

        FileOutputStream out = new FileOutputStream("D:\\workbook.xls");
        wb.write(out);
        out.close();
    }

    private void jTable1CaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTable1CaretPositionChanged

    }//GEN-LAST:event_jTable1CaretPositionChanged

    private void jTable1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyTyped

    }//GEN-LAST:event_jTable1KeyTyped

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        try {
            // TODO add your handling code here:
            writetoexcel();
            //writereplacement();
        } catch (IOException ex) {
            Logger.getLogger(Account.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        long result = Long.parseLong(jTextField6.getText()) + Long.parseLong(jTextField4.getText());
        jTextField8.setText(Long.toString(result));
        result = result - Long.parseLong(jTextField10.getText());
        jTextField13.setText(Long.toString(result));
        jTextField18.setText(jTextField16.getText());
        result = result - Long.parseLong(jTextField16.getText());
        jTextField20.setText(Long.toString(result));
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField11ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField11ActionPerformed

    private void jTable2CaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTable2CaretPositionChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTable2CaretPositionChanged

    private void jTable2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable2KeyPressed
        // TODO add your handling code here:
        int index = jTable2.getSelectedRow();
        //System.out.println(index);
        DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
        int no, number = model.getRowCount();
        no = number;
        if (model.getValueAt(index, 1) != null) {

            int quantity = Integer.parseInt(model.getValueAt(index, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(index, 3).toString());
            Object[] row = { null, null, 0, 0, 0 };
            long total = quantity * rate;
            model.setValueAt(total, index, 4);

            System.out.println(model.getValueAt(number - 1, 1));
            if (model.getValueAt(number - 1, 1) != null)
                model.addRow(row);
            else
                number--;
            long total1 = 0;
            for (int i = 0; i < number; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 4).toString());
            }
            //System.out.println(total1);
            jTextField10.setText(Long.toString(total1));
        }
        if (model.getValueAt(no - 1, 1) == null)
            no--;
        for (int j = 0; j < no; j++) {
            int quantity = Integer.parseInt(model.getValueAt(j, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(j, 3).toString());
            Object[] row = { null, null, 0, 0, 0 };
            long total = quantity * rate;
            model.setValueAt(total, j, 4);
            long total1 = 0;
            for (int i = 0; i < no; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 4).toString());
            }
            //System.out.println(total1);
            jTextField10.setText(Long.toString(total1));
        }

    }//GEN-LAST:event_jTable2KeyPressed

    private void jTable2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable2KeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTable2KeyTyped

    private void jTextField9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField9ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField9ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        jPanel2.setVisible(false);
        jPanel5.setVisible(false);
        jPanel4.setVisible(true);
        long result = Long.parseLong(jTextField6.getText()) + Long.parseLong(jTextField4.getText());
        jTextField8.setText(Long.toString(result));
        result = result - Long.parseLong(jTextField10.getText());
        jTextField13.setText(Long.toString(result));
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        jPanel4.setVisible(false);
        jPanel5.setVisible(false);
        jPanel2.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        jPanel2.setVisible(false);
        jPanel4.setVisible(false);
        jPanel5.setVisible(true);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        jPanel4.setVisible(false);
        jPanel5.setVisible(false);
        jPanel2.setVisible(true);
        long result = Long.parseLong(jTextField6.getText()) + Long.parseLong(jTextField4.getText());
        jTextField8.setText(Long.toString(result));
        result = result - Long.parseLong(jTextField10.getText());
        jTextField13.setText(Long.toString(result));
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        jPanel2.setVisible(false);
        jPanel5.setVisible(false);
        jPanel4.setVisible(true);
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        jPanel2.setVisible(false);
        jPanel4.setVisible(false);
        jPanel5.setVisible(true);
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField12ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField12ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        if (jTable1.getSelectedRow() != -1) {
            // remove selected row from the model
            model.removeRow(jTable1.getSelectedRow());
        }
        //DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        int no = model.getRowCount();
        if (model.getValueAt(no - 1, 1) == null)
            no--;
        for (int j = 0; j < no; j++) {
            int quantity = Integer.parseInt(model.getValueAt(j, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(j, 3).toString());
            Object[] row = { null, null, 0, 0, 0 };
            long total = quantity * rate;
            model.setValueAt(total, j, 4);
            long total1 = 0;
            for (int i = 0; i < no; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 4).toString());
            }
            //System.out.println(total1);
            jTextField4.setText(Long.toString(total1));
        }
        long result = Long.parseLong(jTextField6.getText()) + Long.parseLong(jTextField4.getText());
        jTextField8.setText(Long.toString(result));
        result = result - Long.parseLong(jTextField10.getText());
        jTextField13.setText(Long.toString(result));
        jTextField18.setText(jTextField16.getText());
        result = result - Long.parseLong(jTextField16.getText());
        jTextField20.setText(Long.toString(result));
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
        if (jTable2.getSelectedRow() != -1) {
            // remove selected row from the model
            model.removeRow(jTable2.getSelectedRow());
        }
        //DefaultTableModel model1 = (DefaultTableModel) jTable2.getModel();
        int no1 = model.getRowCount();
        if (model.getValueAt(no1 - 1, 1) == null)
            no1--;
        for (int j = 0; j < no1; j++) {
            int quantity = Integer.parseInt(model.getValueAt(j, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(j, 3).toString());
            Object[] row = { null, null, 0, 0, 0 };
            long total = quantity * rate;
            model.setValueAt(total, j, 4);
            long total1 = 0;
            for (int i = 0; i < no1; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 4).toString());
            }
            //System.out.println(total1);
            jTextField10.setText(Long.toString(total1));
        }
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jTextField14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField14ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField14ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        jPanel2.setVisible(false);
        jPanel5.setVisible(false);
        jPanel4.setVisible(true);
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        jPanel2.setVisible(false);
        jPanel4.setVisible(false);
        jPanel5.setVisible(true);
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        DefaultTableModel model = (DefaultTableModel) jTable3.getModel();
        if (jTable3.getSelectedRow() != -1) {
            // remove selected row from the model
            model.removeRow(jTable3.getSelectedRow());
        }
        int no = model.getRowCount();
        if (model.getValueAt(no - 1, 0) == null)
            no--;
        for (int j = 0; j < no; j++) {
            long total1 = 0;
            for (int i = 0; i < no; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 1).toString());
            }
            //System.out.println(total1);
            jTextField16.setText(Long.toString(total1));
        }
    }//GEN-LAST:event_jButton13ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        jPanel4.setVisible(false);
        jPanel5.setVisible(false);
        jPanel2.setVisible(true);
        long result = Long.parseLong(jTextField6.getText()) + Long.parseLong(jTextField4.getText());
        jTextField8.setText(Long.toString(result));
        result = result - Long.parseLong(jTextField10.getText());
        jTextField13.setText(Long.toString(result));
        jTextField18.setText(jTextField16.getText());
        result = result - Long.parseLong(jTextField16.getText());
        jTextField20.setText(Long.toString(result));
    }//GEN-LAST:event_jButton14ActionPerformed

    private void jTextField15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField15ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField15ActionPerformed

    private void jTextField19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField19ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField19ActionPerformed

    private void jTable3KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable3KeyPressed
        int index = jTable3.getSelectedRow();
        //System.out.println(index);
        DefaultTableModel model = (DefaultTableModel) jTable3.getModel();
        int no, number = model.getRowCount();
        no = number;
        if (model.getValueAt(index, 0) != null) {

            /*int quantity = Integer.parseInt(model.getValueAt(index, 2).toString());
            int rate = Integer.parseInt(model.getValueAt(index, 3).toString());
            Object[] row = {null,null,0,0,0};
            long total = quantity * rate;
            model.setValueAt(total, index, 4);*/
            Object[] row = { null, 0 };
            System.out.println(model.getValueAt(number - 1, 1));
            if (model.getValueAt(number - 1, 0) != null)
                model.addRow(row);
            else
                number--;
            long total1 = 0;
            for (int i = 0; i < number; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 1).toString());
            }
            //System.out.println(total1);
            jTextField16.setText(Long.toString(total1));
        }
        if (model.getValueAt(no - 1, 0) == null)
            no--;
        for (int j = 0; j < no; j++) {
            /* int quantity = Integer.parseInt(model.getValueAt(j, 2).toString());
             int rate = Integer.parseInt(model.getValueAt(j, 3).toString());
             Object[] row = {null,null,0,0,0};
             long total = quantity * rate;
             model.setValueAt(total, j, 4);*/
            long total1 = 0;
            for (int i = 0; i < no; i++) {
                total1 = total1 + Integer.parseInt(model.getValueAt(i, 1).toString());
            }
            //System.out.println(total1);
            jTextField16.setText(Long.toString(total1));
        }

    }//GEN-LAST:event_jTable3KeyPressed

    private void jTextField13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField13ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField13ActionPerformed

    private void fillData(File file) throws BiffException {
        DefaultTableModel model = null;
        workbook = null;
        data = new Vector();
        Object o = new Object[1000][]; /*{
                                       {null, null,  new Integer(0),  new Integer(0), null}
                                       }*/
        headers = new Vector();
        try {
            try {
                workbook = jxl.Workbook.getWorkbook(file);
            } catch (IOException ex) {
                Logger.getLogger(Account.class.getName()).log(Level.SEVERE, null, ex);
            }
            jxl.Sheet sheet = workbook.getSheet(0);

            headers.clear();
            jxl.Cell cell1 = sheet.getCell(0, 1);
            headers.add("Date");
            cell1 = sheet.getCell(1, 1);
            headers.add("Goods");
            cell1 = sheet.getCell(2, 1);
            headers.add("Quantity");
            cell1 = sheet.getCell(3, 1);
            headers.add("Rate");
            cell1 = sheet.getCell(4, 1);
            headers.add("Total");

            data.clear();

            jxl.Cell cell;
            cell = sheet.getCell(0, 0);
            //d.add(cell.getContents());
            jTextField1.setText(cell.getContents());
            for (int j = 2; j < sheet.getRows(); j++) {
                Vector d = new Vector();

                cell = sheet.getCell(1, j);
                // Object o = "Grand Total";
                String s = cell.getContents();
                System.out.println(cell.getContents() + " ");
                String s1 = "";
                if (s.equals(s1)) {
                    System.out.println(j);
                    break;
                }
                //o[j] =d;
                int i;
                for (i = 0; i < 5; i++) {

                    cell = sheet.getCell(i, j);
                    // o[j][i]= cell.getContents();

                    if (i == 2 || i == 3)
                        d.add(new Integer(Integer.parseInt(cell.getContents().toString())));
                    //System.out.print(cell.getContents()+" ");

                    else
                        d.add(cell.getContents());

                }
                cell = sheet.getCell(4, j + 3);
                jTextField6.setText(cell.getContents());
                //d.add("\n");
                //System.out.println();
                data.add(d);

            }
            Vector d = new Vector();
            d.add(null);
            d.add(null);
            d.add(0);
            d.add(0);
            d.add(0);
            data.add(d);
            model = new DefaultTableModel(data, headers);
            jTable1.setModel(new DefaultTableModel(data, headers) {
                Class[] types = new Class[] { java.lang.Object.class, java.lang.Object.class,
                        java.lang.Integer.class, java.lang.Integer.class, java.lang.Long.class };
                boolean[] canEdit = new boolean[] { true, true, true, true, false };

                public Class getColumnClass(int columnIndex) {
                    return types[columnIndex];
                }

                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit[columnIndex];
                }
            });
            refresh();

        } catch (BiffException e) {
            e.printStackTrace();
        }
    }

    private void fillreplace(File file) {
        DefaultTableModel model = null;
        workbook = null;
        data = new Vector();
        Object o = new Object[1000][]; /*{
                                       {null, null,  new Integer(0),  new Integer(0), null}
                                       }*/
        headers = new Vector();
        try {
            try {
                workbook = jxl.Workbook.getWorkbook(file);
            } catch (IOException ex) {
                Logger.getLogger(Account.class.getName()).log(Level.SEVERE, null, ex);
            }
            jxl.Sheet sheet = workbook.getSheet(0);

            headers.clear();
            jxl.Cell cell1 = sheet.getCell(0, 1);
            headers.add("Date");
            cell1 = sheet.getCell(1, 1);
            headers.add("Goods");
            cell1 = sheet.getCell(2, 1);
            headers.add("Quantity");
            cell1 = sheet.getCell(3, 1);
            headers.add("Rate");
            cell1 = sheet.getCell(4, 1);
            headers.add("Total");

            data.clear();

            jxl.Cell cell;
            //cell = sheet.getCell(0, 0);
            //d.add(cell.getContents());
            //jTextField1.setText(cell.getContents());
            for (int j = 2; j < sheet.getRows(); j++) {
                Vector d = new Vector();

                cell = sheet.getCell(7, j);
                // Object o = "Grand Total";
                String s = cell.getContents();
                System.out.println(cell.getContents() + " ");
                String s1 = "";
                if (s.equals(s1)) {
                    System.out.println(j);
                    break;
                }
                //o[j] =d;
                int i;
                for (i = 6; i < 11; i++) {

                    cell = sheet.getCell(i, j);
                    // o[j][i]= cell.getContents();

                    if (i == 2 || i == 3)
                        d.add(new Integer(Integer.parseInt(cell.getContents().toString())));
                    //System.out.print(cell.getContents()+" ");

                    else
                        d.add(cell.getContents());

                }

                //d.add("\n");
                //System.out.println();
                data.add(d);

            }
            Vector d = new Vector();
            d.add(null);
            d.add(null);
            d.add(0);
            d.add(0);
            d.add(0);
            data.add(d);
            model = new DefaultTableModel(data, headers);
            jTable2.setModel(new DefaultTableModel(data, headers) {
                Class[] types = new Class[] { java.lang.Object.class, java.lang.Object.class,
                        java.lang.Integer.class, java.lang.Integer.class, java.lang.Long.class };
                boolean[] canEdit = new boolean[] { true, true, true, true, false };

                public Class getColumnClass(int columnIndex) {
                    return types[columnIndex];
                }

                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit[columnIndex];
                }
            });
            refresh();

        } catch (BiffException e) {
            e.printStackTrace();
        }
    }

    private void fillpay(File file) {
        DefaultTableModel model = null;
        workbook = null;
        data = new Vector();
        Object o = new Object[1000][]; /*{
                                       {null, null,  new Integer(0),  new Integer(0), null}
                                       }*/
        headers = new Vector();
        try {
            try {
                workbook = jxl.Workbook.getWorkbook(file);
            } catch (IOException ex) {
                Logger.getLogger(Account.class.getName()).log(Level.SEVERE, null, ex);
            }
            jxl.Sheet sheet = workbook.getSheet(0);

            headers.clear();
            jxl.Cell cell1 = sheet.getCell(0, 1);
            headers.add("Date");
            cell1 = sheet.getCell(1, 1);
            headers.add("Payment");

            data.clear();

            jxl.Cell cell;
            int k = 0, y = 0;
            for (int j = 2; j < sheet.getRows(); j++) {
                Vector d = new Vector();

                cell = sheet.getCell(0, j);
                // Object o = "Grand Total";
                String s = cell.getContents();
                //System.out.println(cell.getContents()+" ");
                String s1 = "Payment";
                if (s.equals(s1)) {
                    // System.out.println(j);
                    k = j;
                    break;
                }
            }
            for (int j = 2 + k; j < sheet.getRows(); j++) {
                Vector d = new Vector();

                cell = sheet.getCell(0, j);
                // Object o = "Grand Total";
                String s = cell.getContents();
                System.out.println(cell.getContents() + " ");
                String s1 = "Payment Total";
                if (s.equals(s1)) {
                    //System.out.println(j);
                    y = j;
                    break;
                }
            }
            for (int j = 2 + k; j < y - 1; j++) {
                Vector d = new Vector();

                cell = sheet.getCell(0, j);
                // Object o = "Grand Total";
                String s = cell.getContents();
                /*System.out.println(cell.getContents()+" ");
                String s1 = "Payment Total";
                if(s.equals(s1)){
                    System.out.println(j);
                    break;
                }*/
                //o[j] =d;
                int i;
                for (i = 0; i < 2; i++) {

                    cell = sheet.getCell(i, j);
                    d.add(cell.getContents());

                }

                //d.add("\n");
                //System.out.println();
                data.add(d);

            }
            Vector d = new Vector();
            d.add(null);
            d.add(0);
            data.add(d);
            model = new DefaultTableModel(data, headers);
            jTable3.setModel(new DefaultTableModel(data, headers) {
                Class[] types = new Class[] { java.lang.Object.class, java.lang.Integer.class };

                public Class getColumnClass(int columnIndex) {
                    return types[columnIndex];
                }
            });
            refresh();

        } catch (BiffException e) {
            e.printStackTrace();
        }
    }

    private void open() throws BiffException {
        jChooser = new JFileChooser();
        jChooser.showOpenDialog(null);

        File file = jChooser.getSelectedFile();
        if (!file.getName().endsWith("xls")) {
            JOptionPane.showMessageDialog(null, "Please select only Excel file.", "Error",
                    JOptionPane.ERROR_MESSAGE);
        } else {
            fillData(file);
            fillreplace(file);
            fillpay(file);
            jPanel2.setVisible(true);
            jPanel3.setVisible(false);
            jPanel4.setVisible(false);
            jPanel5.setVisible(false);
            refresh();
        }
    }

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        try {
            open();

        } catch (BiffException ex) {
            Logger.getLogger(Account.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//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(Account.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Account.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Account.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Account.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() {
                Account a = new Account();
                a.setVisible(true);
                a.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/Logo3a.jpg")).getImage());
            }
        });
    }

    private String choosertitle;
    private Vector data, headers;
    private jxl.Workbook workbook;
    private JFileChooser jChooser, chooser;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    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.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField13;
    private javax.swing.JTextField jTextField14;
    private javax.swing.JTextField jTextField15;
    private javax.swing.JTextField jTextField16;
    private javax.swing.JTextField jTextField17;
    private javax.swing.JTextField jTextField18;
    private javax.swing.JTextField jTextField19;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField20;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration//GEN-END:variables
}