vinci.project2.pkg1.View.java Source code

Java tutorial

Introduction

Here is the source code for vinci.project2.pkg1.View.java

Source

/*
 * The MIT License (MIT)
    
 * Copyright (c) 2014 Michael D. Vinci
    
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
    
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
    
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package vinci.project2.pkg1;

import java.awt.Color;
import static java.awt.Color.black;
import static java.awt.Color.red;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import javax.swing.table.DefaultTableModel;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author MikeVinci
 */
public class View extends javax.swing.JFrame {

    /**
     *  initialize Year array list
     */
    private final ArrayList<Year> yearArray = new ArrayList<>();

    private double post = 0, totalD = 0, iTax, preBal = 0, postBal = 0, prevBal = 0, year = 0, prevPre = 0,
            capRateGains, preCont = 0, postCont = 0, ror, year2 = 0, total = 0, prevPostTax = 0, postTax = 0;
    private int age, retAge, loopVar, ageOG;
    private final BufferedReader reader = null;

    private final Retirement r = new Retirement();
    private final graphDataset gd = new graphDataset();

    private final XYSeries xySeries1 = new XYSeries("Pre Taxes");
    private final XYSeries xySeries2 = new XYSeries("Post Taxes");
    private final XYSeries xySeries3 = new XYSeries("Total");

    /**
     * Creates new form View
     */
    public View() {
        initComponents();
        ageField.requestFocus();
    }

    /**
     * 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() {

        fileChooser = new javax.swing.JFileChooser();
        saveFrame = new javax.swing.JFrame();
        jLabel2 = new javax.swing.JLabel();
        saveVTextField = new javax.swing.JTextField();
        saveVButton = new javax.swing.JButton();
        loadFrame = new javax.swing.JFrame();
        jLabel4 = new javax.swing.JLabel();
        loadVTextField = new javax.swing.JTextField();
        loadButton = new javax.swing.JButton();
        ageField = new javax.swing.JTextField();
        retAgeField = new javax.swing.JTextField();
        preBalField = new javax.swing.JTextField();
        preContField = new javax.swing.JTextField();
        rorField = new javax.swing.JTextField();
        iTaxField = new javax.swing.JTextField();
        capRateGainsField = new javax.swing.JTextField();
        postBalField = new javax.swing.JTextField();
        postContField = new javax.swing.JTextField();
        calcButton = new javax.swing.JButton();
        resetButton1 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        outputTable = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        chartFrame1 = new javax.swing.JInternalFrame();
        rorLabel = new javax.swing.JLabel();
        preContLabel = new javax.swing.JLabel();
        postContLabel = new javax.swing.JLabel();
        preBalLabel = new javax.swing.JLabel();
        postBalLabel = new javax.swing.JLabel();
        retAgeLabel = new javax.swing.JLabel();
        ageLabel = new javax.swing.JLabel();
        capRateGainsLabel = new javax.swing.JLabel();
        iTaxLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        saveMenuItem = new javax.swing.JMenuItem();
        loadMenuIten = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();

        fileChooser.setDialogTitle("File Chooser:");

        jLabel2.setText("Filename: ");

        saveVButton.setText("Save");
        saveVButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveVButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout saveFrameLayout = new javax.swing.GroupLayout(saveFrame.getContentPane());
        saveFrame.getContentPane().setLayout(saveFrameLayout);
        saveFrameLayout.setHorizontalGroup(saveFrameLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(saveFrameLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveVTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveVButton, javax.swing.GroupLayout.PREFERRED_SIZE, 57,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));
        saveFrameLayout.setVerticalGroup(saveFrameLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(saveFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(saveVTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(saveVButton)));

        jLabel4.setText("Filename: ");

        loadButton.setText("Load");
        loadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout loadFrameLayout = new javax.swing.GroupLayout(loadFrame.getContentPane());
        loadFrame.getContentPane().setLayout(loadFrameLayout);
        loadFrameLayout.setHorizontalGroup(loadFrameLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(loadFrameLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel4).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(loadVTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(loadButton, javax.swing.GroupLayout.PREFERRED_SIZE, 57,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));
        loadFrameLayout.setVerticalGroup(loadFrameLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(loadFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(loadVTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(loadButton)));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        ageField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                ageFieldFocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                ageFieldFocusLost(evt);
            }
        });

        retAgeField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                retAgeFieldFocusLost(evt);
            }
        });

        preBalField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                preBalFieldFocusLost(evt);
            }
        });
        preBalField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                preBalFieldActionPerformed(evt);
            }
        });

        preContField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                preContFieldFocusLost(evt);
            }
        });

        rorField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                rorFieldFocusLost(evt);
            }
        });

        iTaxField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                iTaxFieldFocusLost(evt);
            }
        });

        capRateGainsField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                capRateGainsFieldFocusLost(evt);
            }
        });

        postBalField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                postBalFieldFocusLost(evt);
            }
        });

        postContField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                postContFieldFocusLost(evt);
            }
        });

        calcButton.setText("Calculate");
        calcButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calcButtonActionPerformed(evt);
            }
        });

        resetButton1.setText("Reset");
        resetButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButton1ActionPerformed(evt);
            }
        });

        outputTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Age", "Pre-Tax Balance", "Post-Tax Balance", "Total Balance" }));
        outputTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(outputTable);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE)
                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
                        .addContainerGap()));

        jTabbedPane1.addTab("Text", jPanel1);

        chartFrame1.setVisible(true);

        javax.swing.GroupLayout chartFrame1Layout = new javax.swing.GroupLayout(chartFrame1.getContentPane());
        chartFrame1.getContentPane().setLayout(chartFrame1Layout);
        chartFrame1Layout.setHorizontalGroup(chartFrame1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 653, Short.MAX_VALUE));
        chartFrame1Layout.setVerticalGroup(chartFrame1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 434, Short.MAX_VALUE));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout
                        .createSequentialGroup().addContainerGap().addComponent(chartFrame1).addContainerGap()));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(chartFrame1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)));

        jTabbedPane1.addTab("Graph", jPanel2);

        rorLabel.setText(" Rate of Return *");

        preContLabel.setText(" Pre Tax Cont");

        postContLabel.setText(" Post Tax Cont");

        preBalLabel.setText(" Pre Tax Bal");

        postBalLabel.setText(" Post Tax Bal");

        retAgeLabel.setText(" Retirement Age");

        ageLabel.setText(" Age");

        capRateGainsLabel.setText(" Cap Gains Rate *");

        iTaxLabel.setText("Income Tax Rate *");

        jLabel1.setText("* Enter as");

        jLabel3.setText("  Decimal");

        jMenu1.setText("File");

        saveMenuItem.setText("Save");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(saveMenuItem);

        loadMenuIten.setText("Load");
        loadMenuIten.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadMenuItenActionPerformed(evt);
            }
        });
        jMenu1.add(loadMenuIten);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(exitMenuItem);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(rorField).addComponent(rorLabel))
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(retAgeField, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(preBalField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(preBalLabel)))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addComponent(postBalLabel).addComponent(postBalField).addComponent(
                                                        capRateGainsField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(preContField, javax.swing.GroupLayout.PREFERRED_SIZE, 89,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(preContLabel)).addGap(18, 18, 18)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(postContLabel)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(postContField,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 89,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel3).addComponent(jLabel1)))))
                                .addGroup(layout.createSequentialGroup().addComponent(ageLabel).addGap(79, 79, 79)
                                        .addComponent(iTaxLabel))
                                .addGroup(layout.createSequentialGroup().addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(retAgeLabel).addComponent(ageField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 89,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(capRateGainsLabel))
                                                .addGroup(
                                                        layout.createSequentialGroup().addGap(7, 7, 7).addComponent(
                                                                iTaxField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                89, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup().addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addGap(6, 6, 6).addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(calcButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(resetButton1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        196, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(0, 0, Short.MAX_VALUE))
                                        .addComponent(jSeparator3))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 710,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(ageLabel).addComponent(iTaxLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(ageField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(iTaxField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(retAgeLabel).addComponent(capRateGainsLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(retAgeField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(capRateGainsField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(preBalLabel).addComponent(postBalLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(preBalField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(postBalField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(preContLabel).addComponent(postContLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(postContField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(preContField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(rorLabel).addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(rorField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel3))
                                .addGap(6, 6, 6)
                                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(calcButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(resetButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addComponent(jTabbedPane1))));

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

    private void calcButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calcButtonActionPerformed
        try {
            Integer.parseInt(ageField.getText());
            Integer.parseInt(retAgeField.getText());
            Double.parseDouble(capRateGainsField.getText());
            Double.parseDouble(iTaxField.getText());
            Double.parseDouble(rorField.getText());
            Double.parseDouble(preBalField.getText());
            Double.parseDouble(postBalField.getText());
            Double.parseDouble(preContField.getText());
            Double.parseDouble(postContField.getText());

            Retirement r = new Retirement();

            clearXY();
            getVars();

            loopVar = retAge - age;
            ror = 1 + ror;

            DefaultTableModel model = (DefaultTableModel) outputTable.getModel();
            model.setRowCount(0);

            for (int q = 0; q < loopVar + 1; q++) {
                String preTaxS = r.preTaxM(q, loopVar, ror, year, preBal, preCont, iTax);
                String postTaxS = r.postTaxM(q, loopVar, year, ror, postBal, capRateGains, preCont, postTax);

                year = Double.parseDouble(preTaxS);
                post = Double.parseDouble(postTaxS);

                String totalS = r.total(total, year, post);

                totalD = Double.parseDouble(totalS);

                yearArray.add(new Year(age, year, post, totalD));

                Object[] row = { age, "$" + preTaxS, "$" + postTaxS, "$" + String.format("%.2f", totalD) };
                model.addRow(row);

                addXY();

                age++;
            }

            outputTable.setModel(model);

            setChart();
        } catch (NumberFormatException e) {
            calcButton.setEnabled(false);
        }
    }//GEN-LAST:event_calcButtonActionPerformed

    /**
     * Assigns all jTextFields to their respective variables
     */
    private void getVars() {
        String ageTest = ageField.getText();

        try {
            if ("".equals(ageTest)) {
                throw new NumberFormatException();
            }
            age = Integer.parseInt(ageField.getText());
            ageOG = age;
            capRateGains = Double.parseDouble(capRateGainsField.getText());
            iTax = Double.parseDouble(iTaxField.getText());
            retAge = Integer.parseInt(retAgeField.getText());
            preCont = Double.parseDouble(preContField.getText());
            postCont = Double.parseDouble(postContField.getText());
            ror = Double.parseDouble(rorField.getText());
            preBal = Double.parseDouble(preBalField.getText());
            postBal = Double.parseDouble(postBalField.getText());
        } catch (NumberFormatException e) {
        }
    }

    /**
     * Resets XYSeries to empty to rewrite graph line
     */
    private void clearXY() {
        xySeries1.clear();
        xySeries2.clear();
        xySeries3.clear();
    }

    /**
     * Adds information to XYSeries
     */
    private void addXY() {
        xySeries1.add(age, year);
        xySeries2.add(age, post);
        xySeries3.add(age, totalD);
    }

    /**
     * creates the actual chart w/ dimensions, et al
     */
    private JFreeChart createChart(final XYDataset dataset) {

        final JFreeChart chart = ChartFactory.createXYLineChart("Pre/Post Taxes/Totals", "Age", "Amounts ($)",
                dataset, PlotOrientation.VERTICAL, true, true, false);
        chart.setBackgroundPaint(Color.white);

        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, false);
        renderer.setSeriesShapesVisible(1, false);
        plot.setRenderer(renderer);

        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        return chart;
    }

    /**
     * Initializes the chart
     */
    private void setChart() {
        final JFreeChart chart = createChart(gd.createDataset(xySeries1, xySeries2, xySeries3));
        ChartPanel chartPanel = new ChartPanel(chart);

        chartPanel.setSize(400, 300);

        ChartFrame chartFrame = new ChartFrame("Taxes", chart);
        chartFrame.setSize(400, 300);

        chartFrame.add(chartPanel);
        chartFrame.pack();
        chartFrame.setVisible(false);

        chartFrame1.add(chartPanel);

        chartFrame1.setSize(400, 300);
        chartFrame1.repaint();
        chartFrame1.revalidate();
    }

    /**
     * Try/Catch when focus is lost for the rate of return Field
     */
    private void rorFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_rorFieldFocusLost
        percentTest(rorField, rorLabel);
    }//GEN-LAST:event_rorFieldFocusLost

    /**
     * resets JTextFields to blank
     */
    private void resetButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButton1ActionPerformed
        ageField.setText("");
        capRateGainsField.setText("");
        iTaxField.setText("");
        retAgeField.setText("");
        preContField.setText("");
        postContField.setText("");
        rorField.setText("");
        preBalField.setText("");
        postBalField.setText("");
    }//GEN-LAST:event_resetButton1ActionPerformed

    /**
     * Try/Catch when focus is lost for the Capital Gains Rate Field
     */
    private void capRateGainsFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_capRateGainsFieldFocusLost
        percentTest(capRateGainsField, capRateGainsLabel);
    }//GEN-LAST:event_capRateGainsFieldFocusLost

    /**
     * Try/Catch when focus is lost for the Retirement Age Field
     */
    private void retAgeFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_retAgeFieldFocusLost
        String retTest = retAgeField.getText();

        if (retTest.equals("")) {
            retAgeLabel.setForeground(red);
            calcButton.setEnabled(false);
        } else {
            try {
                int ageTest = Integer.parseInt(ageField.getText());
                int retAgeTest = Integer.parseInt(retAgeField.getText());

                if ((ageTest < retAgeTest) && (retAgeTest > 0) && (retAgeTest < 120)) {
                    retAgeLabel.setForeground(black);
                    calcButton.setEnabled(true);
                } else {
                    retAgeLabel.setForeground(red);
                    calcButton.setEnabled(false);
                }
            } catch (NumberFormatException e) {
                retAgeLabel.setForeground(red);
                calcButton.setEnabled(false);
            }
        }
    }//GEN-LAST:event_retAgeFieldFocusLost

    /**
     * Try/Catch when focus is lost for the income Tax Field
     */
    private void iTaxFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_iTaxFieldFocusLost
        percentTest(iTaxField, iTaxLabel);
    }//GEN-LAST:event_iTaxFieldFocusLost

    /**
     * Try/Catch when focus is lost for the Post Tax Balance Field
     */
    private void postBalFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_postBalFieldFocusLost
        tryTest(postBalField, postBalLabel);
    }//GEN-LAST:event_postBalFieldFocusLost

    /**
     * Try/Catch when focus is lost for the Previous Tax Balance Field
     */
    private void preBalFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_preBalFieldFocusLost
        tryTest(preBalField, preBalLabel);
    }//GEN-LAST:event_preBalFieldFocusLost

    /**
     * Try/Catch when focus is lost for the Post Tax Contribution Field
     */
    private void postContFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_postContFieldFocusLost
        tryTest(postContField, postContLabel);
    }//GEN-LAST:event_postContFieldFocusLost

    /**
     * Try/Catch when focus is lost for the Pre Tax Contribution Field
     */
    private void preContFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_preContFieldFocusLost
        tryTest(preContField, preContLabel);
    }//GEN-LAST:event_preContFieldFocusLost

    /**
     * Try/Catch when focus is lost for the Age Field
     */
    private void ageFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ageFieldFocusLost
        numTest(ageField, ageLabel);
    }//GEN-LAST:event_ageFieldFocusLost

    /**
     * first attempt at error handling
     */
    private void ageFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ageFieldFocusGained
        preContField.setForeground(black);
    }//GEN-LAST:event_ageFieldFocusGained

    /**
     * Displays filename setter when save menu item selected
     */
    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        saveFrame.setSize(260, 60);
        saveFrame.setVisible(true);
    }//GEN-LAST:event_saveMenuItemActionPerformed

    /**
     * Exit program when menu item is selected
     */
    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    /**
     * displays file chooser when file menu item selected
     */
    private void loadMenuItenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMenuItenActionPerformed
        loadFrame.setSize(260, 60);
        loadFrame.setVisible(true);
    }//GEN-LAST:event_loadMenuItenActionPerformed

    /**
     * saves JTextFields on pop-up, 
     */
    private void saveVButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveVButtonActionPerformed
        String filename = saveVTextField.getText();

        try {
            try (BufferedWriter outfile = new BufferedWriter(new FileWriter(filename))) {
                saveSerial(filename);
            }
            saveFrame.dispose();
        } catch (IOException ex) {
            Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_saveVButtonActionPerformed

    /**
     * Serialize the bitch
     * @param filename
     * @throws java.io.IOException
     */
    public void saveSerial(String filename) throws IOException {
        Save save = new Save(ageOG, retAge, capRateGains, preCont, postCont, preBal, postBal, iTax, ror);

        try {
            FileOutputStream fos = new FileOutputStream(filename);

            BufferedOutputStream bos = new BufferedOutputStream(fos);

            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(save);
            oos.close();
            fos.close();
        } catch (IOException i) {
        }

    }

    /**
     * Load me, baby
     */
    private void loadSerial(String filename) throws FileNotFoundException, IOException, ClassNotFoundException {

        try {
            FileInputStream fis = new FileInputStream(filename);

            System.out.println(filename);

            BufferedInputStream bis = new BufferedInputStream(fis);
            ObjectInputStream ois = new ObjectInputStream(bis);
            Save save = (Save) ois.readObject();

            ageField.setText(String.valueOf(save.age));
            capRateGainsField.setText(String.valueOf(save.capRateGains));
            iTaxField.setText(String.valueOf(save.iTax));
            retAgeField.setText(String.valueOf(save.retAge));
            preContField.setText(String.valueOf(save.preCont));
            postContField.setText(String.valueOf(save.postCont));
            rorField.setText(String.format("%.2f", (save.ror)));
            preBalField.setText(String.valueOf(save.preBal));
            postBalField.setText(String.valueOf(save.postBal));

            fis.close();
            ois.close();
        } catch (ClassNotFoundException c) {
        }
    }

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

    private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed
        try {
            String filename = loadVTextField.getText();

            loadSerial(filename);
        } catch (IOException | ClassNotFoundException ex) {
            Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_loadButtonActionPerformed

    /**
     * @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 | InstantiationException | IllegalAccessException
                | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(View.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new View().setVisible(true);
            }
        });
    }

    private void percentTest(JTextField fieldName, JLabel labelName) {
        String testS = fieldName.getText();

        if (testS.equals("")) {
            labelName.setForeground(red);
            calcButton.setEnabled(false);
        } else {
            try {
                double testD = Double.parseDouble(fieldName.getText());
                if ((testD >= 0) && (testD <= 1)) {
                    Double.parseDouble(iTaxField.getText());
                    labelName.setForeground(black);
                    calcButton.setEnabled(true);
                } else
                    labelName.setForeground(red);
                calcButton.setEnabled(false);
            } catch (NumberFormatException e) {
                labelName.setForeground(red);
                calcButton.setEnabled(false);
            }
        }
    }

    private void tryTest(JTextField fieldName, JLabel labelName) {
        try {
            Double.parseDouble(fieldName.getText());
            labelName.setForeground(black);
            calcButton.setEnabled(true);
        } catch (NumberFormatException e) {
            labelName.setForeground(red);
            calcButton.setEnabled(false);
        }
    }

    private void numTest(JTextField fieldName, JLabel labelName) {
        String testS = fieldName.getText();

        if (testS.equals("")) {
            labelName.setForeground(red);
            calcButton.setEnabled(false);
        } else {
            try {
                int testI = Integer.parseInt(fieldName.getText());

                if (testI > 0) {
                    labelName.setForeground(black);
                    calcButton.setEnabled(true);
                } else {
                    labelName.setForeground(red);
                    calcButton.setEnabled(false);
                }
            } catch (NumberFormatException e) {
                labelName.setForeground(red);
                calcButton.setEnabled(false);
            }
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ageField;
    private javax.swing.JLabel ageLabel;
    private javax.swing.JButton calcButton;
    private javax.swing.JTextField capRateGainsField;
    private javax.swing.JLabel capRateGainsLabel;
    private javax.swing.JInternalFrame chartFrame1;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JTextField iTaxField;
    private javax.swing.JLabel iTaxLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton loadButton;
    private javax.swing.JFrame loadFrame;
    private javax.swing.JMenuItem loadMenuIten;
    private javax.swing.JTextField loadVTextField;
    private javax.swing.JTable outputTable;
    private javax.swing.JTextField postBalField;
    private javax.swing.JLabel postBalLabel;
    private javax.swing.JTextField postContField;
    private javax.swing.JLabel postContLabel;
    private javax.swing.JTextField preBalField;
    private javax.swing.JLabel preBalLabel;
    private javax.swing.JTextField preContField;
    private javax.swing.JLabel preContLabel;
    private javax.swing.JButton resetButton1;
    private javax.swing.JTextField retAgeField;
    private javax.swing.JLabel retAgeLabel;
    private javax.swing.JTextField rorField;
    private javax.swing.JLabel rorLabel;
    private javax.swing.JFrame saveFrame;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JButton saveVButton;
    private javax.swing.JTextField saveVTextField;
    // End of variables declaration//GEN-END:variables
}