/*
 * DailyPlannerFrame.java
 * Created on April 19, 2005, 12:49 AM
 * author:scott
 * GUI window for bulletinboard/appointments = daily planner
 */
package scott;

import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.*;

public class DailyPlannerFrame extends JFrame {
    
    /**CONSTRUCTOR>Creates new form DailyPlannerFrame */
    public DailyPlannerFrame(int month, int day) {
        initComponents();
        
        appointmentsText.setCaretPosition(0);
        bulletinBoardText.setCaretPosition(0);
        currentMonth = month;
        currentDay = day;
        
        int tempIndex = month - 1;
        panel2Label.setText("APPOINTMENTS FOR: " + MONTH_NAMES[tempIndex] + "," +
                day);
        
        
        
        /*read from appointments.dat file to populate appointment
         *text area*/
        try {
            //try to read from the file i know is there
            FileInputStream fileIn = new FileInputStream(".\\appointments.dat");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            appointments = (Vector) in.readObject();
            
            appointmentsText.setText(printDate(appointments,  month, day));
      
        } catch (java.lang.ClassNotFoundException e){
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
   
        /*read from messages.dat file to populate bulletin
         *board text area*/
        try {
            //try to read from the file i know is there
            FileInputStream fileIn = new FileInputStream(".\\messages.dat");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            Vector messages = (Vector) in.readObject();
            
            for (int i=0; i<messages.size(); i++) {
                MessageBean myBean = (MessageBean)messages.elementAt(i);
                bulletinBoardText.append(myBean.printString());
            }//end 'for'
            
        } catch (java.lang.ClassNotFoundException e){
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        appointmentsText.setCaretPosition(0);
        bulletinBoardText.setCaretPosition(0);
        
        
    }//end constructor
    
    
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        topLeftPanel = new javax.swing.JPanel();
        panel1Label = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        bulletinBoardText = new javax.swing.JTextArea();
        topRightPanel = new javax.swing.JPanel();
        panel2Label = new javax.swing.JLabel();
        navPanel = new javax.swing.JPanel();
        backMonthButton = new javax.swing.JButton();
        backButton = new javax.swing.JButton();
        forwardButton = new javax.swing.JButton();
        forwardMonthButton = new javax.swing.JButton();
        appointmentsPane = new javax.swing.JScrollPane();
        appointmentsText = new javax.swing.JTextArea();
        leftFooterPanel = new javax.swing.JPanel();
        onlyPanel = new javax.swing.JPanel();
        msgField = new javax.swing.JTextField();
        subjectLabel = new javax.swing.JLabel();
        subjectField = new javax.swing.JTextField();
        msgLabel = new javax.swing.JLabel();
        submitMsgButton = new javax.swing.JButton();
        clearButton1 = new javax.swing.JButton();
        rightFooterPanel = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        timeField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        agentField = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        reasonField = new javax.swing.JTextField();
        submitAptButton = new javax.swing.JButton();
        clearButton2 = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        deleteAppointmentField = new javax.swing.JTextField();
        menuBar = new javax.swing.JMenuBar();
        barMenuA = new javax.swing.JMenu();
        subMenuA1 = new javax.swing.JMenu();
        itemA1_1 = new javax.swing.JMenuItem();
        itemA1_2 = new javax.swing.JMenuItem();
        subMenuA2 = new javax.swing.JMenu();
        itemA2_1 = new javax.swing.JMenuItem();
        itemA2_2 = new javax.swing.JMenuItem();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Daily Planner");
        setBackground(new java.awt.Color(255, 255, 255));
        topLeftPanel.setLayout(new java.awt.GridBagLayout());

        topLeftPanel.setBackground(new java.awt.Color(255, 255, 255));
        topLeftPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
        panel1Label.setFont(new java.awt.Font("Tahoma", 0, 12));
        panel1Label.setForeground(new java.awt.Color(0, 102, 204));
        panel1Label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        panel1Label.setText("BULLETIN BOARD");
        panel1Label.setBorder(new javax.swing.border.EtchedBorder(null, new java.awt.Color(47, 87, 214)));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        topLeftPanel.add(panel1Label, gridBagConstraints);

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        bulletinBoardText.setBackground(new java.awt.Color(240, 236, 236));
        bulletinBoardText.setEditable(false);
        bulletinBoardText.setLineWrap(true);
        jScrollPane1.setViewportView(bulletinBoardText);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        topLeftPanel.add(jScrollPane1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(topLeftPanel, gridBagConstraints);

        topRightPanel.setLayout(new java.awt.GridBagLayout());

        topRightPanel.setBackground(new java.awt.Color(255, 255, 255));
        topRightPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
        panel2Label.setBackground(new java.awt.Color(255, 255, 255));
        panel2Label.setFont(new java.awt.Font("Tahoma", 0, 12));
        panel2Label.setForeground(new java.awt.Color(0, 102, 204));
        panel2Label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        panel2Label.setText("APPOINTMENTS");
        panel2Label.setBorder(new javax.swing.border.EtchedBorder(null, new java.awt.Color(47, 87, 214)));
        panel2Label.setOpaque(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        topRightPanel.add(panel2Label, gridBagConstraints);

        navPanel.setLayout(new java.awt.GridLayout(1, 0));

        backMonthButton.setBackground(new java.awt.Color(255, 255, 255));
        backMonthButton.setIcon(new javax.swing.ImageIcon(".\\left_left.gif"));
        backMonthButton.setToolTipText("move back one month");
        backMonthButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backMonthButtonActionPerformed(evt);
            }
        });

        navPanel.add(backMonthButton);

        backButton.setBackground(new java.awt.Color(255, 255, 255));
        backButton.setIcon(new javax.swing.ImageIcon(".\\left.gif"));
        backButton.setToolTipText("move back one day");
        backButton.setPreferredSize(new java.awt.Dimension(30, 30));
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                displayLastMonth(evt);
            }
        });

        navPanel.add(backButton);

        forwardButton.setBackground(new java.awt.Color(255, 255, 255));
        forwardButton.setIcon(new javax.swing.ImageIcon(".\\right.gif"));
        forwardButton.setToolTipText("move forward one day");
        forwardButton.setPreferredSize(new java.awt.Dimension(30, 30));
        forwardButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                displayNextMonth(evt);
            }
        });

        navPanel.add(forwardButton);

        forwardMonthButton.setBackground(new java.awt.Color(255, 255, 255));
        forwardMonthButton.setIcon(new javax.swing.ImageIcon(".\\right_right.gif"));
        forwardMonthButton.setToolTipText("move forward one month");
        forwardMonthButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                forwardMonthButtonActionPerformed(evt);
            }
        });

        navPanel.add(forwardMonthButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        topRightPanel.add(navPanel, gridBagConstraints);

        appointmentsPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        appointmentsText.setBackground(new java.awt.Color(240, 236, 236));
        appointmentsText.setColumns(80);
        appointmentsText.setEditable(false);
        appointmentsText.setLineWrap(true);
        appointmentsText.setMargin(new java.awt.Insets(7, 7, 7, 7));
        appointmentsPane.setViewportView(appointmentsText);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 99.0;
        topRightPanel.add(appointmentsPane, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(topRightPanel, gridBagConstraints);

        leftFooterPanel.setLayout(new java.awt.GridBagLayout());

        onlyPanel.setLayout(new java.awt.GridBagLayout());

        onlyPanel.setBackground(new java.awt.Color(240, 236, 236));
        onlyPanel.setForeground(new java.awt.Color(0, 102, 153));
        onlyPanel.setPreferredSize(new java.awt.Dimension(270, 220));
        msgField.setToolTipText("Enter your message here:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        onlyPanel.add(msgField, gridBagConstraints);

        subjectLabel.setBackground(new java.awt.Color(240, 236, 236));
        subjectLabel.setFont(new java.awt.Font("MS Sans Serif", 1, 11));
        subjectLabel.setForeground(new java.awt.Color(0, 102, 153));
        subjectLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        subjectLabel.setText("Subject:");
        subjectLabel.setOpaque(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        onlyPanel.add(subjectLabel, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        onlyPanel.add(subjectField, gridBagConstraints);

        msgLabel.setBackground(new java.awt.Color(240, 236, 236));
        msgLabel.setFont(new java.awt.Font("MS Sans Serif", 1, 11));
        msgLabel.setForeground(new java.awt.Color(0, 102, 153));
        msgLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        msgLabel.setText("New Message:");
        msgLabel.setOpaque(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.2;
        onlyPanel.add(msgLabel, gridBagConstraints);

        submitMsgButton.setBackground(new java.awt.Color(0, 0, 0));
        submitMsgButton.setForeground(new java.awt.Color(255, 255, 255));
        submitMsgButton.setText("Submit");
        submitMsgButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addMsgPressed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.weightx = 1.0;
        onlyPanel.add(submitMsgButton, gridBagConstraints);

        clearButton1.setBackground(new java.awt.Color(0, 0, 0));
        clearButton1.setForeground(new java.awt.Color(255, 255, 255));
        clearButton1.setText("Clear");
        clearButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButton1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        onlyPanel.add(clearButton1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        leftFooterPanel.add(onlyPanel, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.1;
        getContentPane().add(leftFooterPanel, gridBagConstraints);

        rightFooterPanel.setLayout(new java.awt.GridBagLayout());

        rightFooterPanel.setBackground(new java.awt.Color(240, 236, 236));
        jLabel9.setText("Time:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        rightFooterPanel.add(jLabel9, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        rightFooterPanel.add(timeField, gridBagConstraints);

        jLabel10.setText("Name:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        rightFooterPanel.add(jLabel10, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightFooterPanel.add(nameField, gridBagConstraints);

        jLabel11.setText("Agent:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        rightFooterPanel.add(jLabel11, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightFooterPanel.add(agentField, gridBagConstraints);

        jLabel12.setText("Reason:");
        jLabel12.setPreferredSize(new java.awt.Dimension(400, 300));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        rightFooterPanel.add(jLabel12, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightFooterPanel.add(reasonField, gridBagConstraints);

        submitAptButton.setBackground(new java.awt.Color(0, 0, 0));
        submitAptButton.setForeground(new java.awt.Color(255, 255, 255));
        submitAptButton.setText("Submit");
        submitAptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitAptButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightFooterPanel.add(submitAptButton, gridBagConstraints);

        clearButton2.setBackground(new java.awt.Color(0, 0, 0));
        clearButton2.setForeground(new java.awt.Color(255, 255, 255));
        clearButton2.setText("Clear");
        clearButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButton2ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightFooterPanel.add(clearButton2, gridBagConstraints);

        deleteButton.setBackground(new java.awt.Color(0, 0, 0));
        deleteButton.setForeground(new java.awt.Color(255, 255, 255));
        deleteButton.setText("Delete Appointment:");
        deleteButton.setToolTipText("Please select an appointment ID NUMBER for deletion");
        deleteButton.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        rightFooterPanel.add(deleteButton, gridBagConstraints);

        deleteAppointmentField.setText("enter ID #");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        rightFooterPanel.add(deleteAppointmentField, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.1;
        getContentPane().add(rightFooterPanel, gridBagConstraints);

        barMenuA.setBorder(new javax.swing.border.MatteBorder(null));
        barMenuA.setLabel("File");
        subMenuA1.setText("Options");
        itemA1_1.setText("Item");
        subMenuA1.add(itemA1_1);

        itemA1_2.setText("Item");
        subMenuA1.add(itemA1_2);

        barMenuA.add(subMenuA1);

        subMenuA2.setLabel("sub - menu");
        itemA2_1.setText("Item");
        subMenuA2.add(itemA2_1);

        itemA2_2.setText("Item");
        subMenuA2.add(itemA2_2);

        barMenuA.add(subMenuA2);

        menuBar.add(barMenuA);

        setJMenuBar(menuBar);

        pack();
    }//GEN-END:initComponents

    private void clearButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButton1ActionPerformed
        msgField.setText("");
        subjectField.setText("");
    }//GEN-LAST:event_clearButton1ActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        try {
        //first, extract 'appointments' vector, we'll need it to write to
        FileInputStream fileIn = new FileInputStream(".\\appointments.dat");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        Vector appointments = (Vector)in.readObject();
        in.close();
       
        int selected = Integer.parseInt(deleteAppointmentField.getText());
        
        //System.out.println("Selected index(value) " + selected );
        System.out.println("appointmentList.toString()");
        int m = currentMonth - 1;
        int d = currentDay - 1;
        ((Vector)((Vector)appointments.elementAt(m)).elementAt(d)).removeElementAt(--selected);
      
        
        
        //now open output file stream and (over)write vector to it
        //bool arg is to set append=true/false
        FileOutputStream fos = new FileOutputStream(".\\appointments.dat");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(appointments);
        oos.flush();
        oos.close();
        fos.close();
           
        this.dispose();
        DailyPlannerFrame dpf = new DailyPlannerFrame(currentMonth, currentDay);
        dpf.setSize(600,500);
        dpf.setVisible(true);
        
        } catch (IOException e) {
        e.printStackTrace();
        } catch (java.lang.ClassNotFoundException e) {
        e.printStackTrace();
        } 
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void clearButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButton2ActionPerformed
       timeField.setText("");
       agentField.setText("");
       nameField.setText("");
       reasonField.setText("");
    }//GEN-LAST:event_clearButton2ActionPerformed

    private void submitAptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitAptButtonActionPerformed
        try {
        //first, extract 'appointments' vector, we'll need it to write to
        FileInputStream fileIn = new FileInputStream(".\\appointments.dat");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        Vector appointments = (Vector)in.readObject();
        in.close();
               
        //put user entry into a bean
        AppointmentBean entry = new AppointmentBean();
        entry.setTime(timeField.getText());
        entry.setName(nameField.getText());
        entry.setAgent(agentField.getText());
        entry.setReason(reasonField.getText());
        
        
        
      
        int m = currentMonth - 1;
        int d = currentDay - 1;
        //store the bean into the underlying beans vector
        ((Vector)((Vector)appointments.elementAt(m)).elementAt(d)).addElement(entry);
      
        
        
        //now open output file stream and (over)write vector to it
        //bool arg is to set append=true/false
        FileOutputStream fos = new FileOutputStream(".\\appointments.dat");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(appointments);
        oos.flush();
        oos.close();
        fos.close();
        
        //System.out.println(currentDay + " " + currentMonth);
        //System.out.println(printDate(appointments,  currentDay, currentMonth));
        //appointmentsText.setText(printDate(appointments,  currentDay, currentMonth));
        //why the hell the above statement doesn't work i don't know
         
    
    
        this.dispose();
        DailyPlannerFrame dpf = new DailyPlannerFrame(currentMonth, currentDay);
        dpf.setSize(600,500);
        dpf.setVisible(true);
        
        } catch (IOException e) {
        e.printStackTrace();
        } catch (java.lang.ClassNotFoundException e) {
        e.printStackTrace();
        } 

    }//GEN-LAST:event_submitAptButtonActionPerformed
    
    private void backMonthButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backMonthButtonActionPerformed
        if(currentMonth==1) { currentMonth = 12; } else { currentMonth--; }
        
        int monthIndex = currentMonth -1;
        appointmentsText.setText(printDate(appointments,  currentMonth, currentDay));
        panel2Label.setText("APPOINTMENTS FOR: " + MONTH_NAMES[monthIndex] + "," +
                currentDay);
        
        
    }//GEN-LAST:event_backMonthButtonActionPerformed
    
    private void forwardMonthButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forwardMonthButtonActionPerformed
        if(currentMonth==12) { currentMonth = 1; } else { currentMonth++; }
        
        int monthIndex = currentMonth -1;
        appointmentsText.setText(printDate(appointments, currentMonth, currentDay));
        panel2Label.setText("APPOINTMENTS FOR: " + MONTH_NAMES[monthIndex] + "," +
                currentDay);
    }//GEN-LAST:event_forwardMonthButtonActionPerformed
    
    private void addMsgPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMsgPressed
        try {
            //first, extract 'messages' vector, we'll need it to save to
            FileInputStream fileIn = new FileInputStream(".\\messages.dat");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            Vector messages = (Vector)in.readObject();
            in.close();
            
            //put user entry into a bean
            MessageBean entry = new MessageBean();
            entry.setSubject(subjectField.getText());
            entry.setMessage(msgField.getText());
            
            //put the bean into the 'messages' Vector
            messages.add(entry);
            
            //now open output file stream and (over)write vector to it
            //bool arg is to set append=true/false
            FileOutputStream fos = new FileOutputStream(".\\messages.dat");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(messages);
            oos.flush();
            oos.close();
            fos.close();
            
            bulletinBoardText.append(entry.printString());
            
        } catch (IOException e) {
            e.printStackTrace();
        } catch (java.lang.ClassNotFoundException e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_addMsgPressed
    
    private void displayLastMonth(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayLastMonth
        
        
        if(currentDay == 1) {
            currentDay = 31;
            if(currentMonth == 1) {
                currentMonth = 12;
            } else {
                currentMonth--;
            }
        } else {
            currentDay--;
        }
        int monthIndex = currentMonth -1;
        //set text area to that day
        appointmentsText.setText(printDate(appointments,  currentMonth, currentDay));
        panel2Label.setText("APPOINTMENTS FOR: " + MONTH_NAMES[monthIndex] + "," +
                currentDay);
        
        
        
    }//GEN-LAST:event_displayLastMonth
    
    private void displayNextMonth(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayNextMonth
        
        if(currentDay == 31) {
            currentDay = 1;
            if(currentMonth == 12) {
                currentMonth = 1;
            } else {
                currentMonth++;
            }
        } else {
            currentDay++;
        }
        int monthIndex = currentMonth -1;
        //set text area to that day
        appointmentsText.setText(printDate(appointments,  currentMonth, currentDay));
        panel2Label.setText("APPOINTMENTS FOR: " + MONTH_NAMES[monthIndex] + "," +
                currentDay);
   
    }//GEN-LAST:event_displayNextMonth
    
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
                //main method for debug and testing purposes and to build
                //ppointments vector - as such should only be used for that purpose
                
                DailyPlannerFrame dpf = new DailyPlannerFrame(10, 5);
                //dpf.setSize(550,500);
                dpf.setVisible(true);
                
                /*
                //create a hard coded bean to populate the bottom bean vectors
                AppointmentBean aptBean = new AppointmentBean();
                aptBean.setAgent("SWeave");
                aptBean.setReason("Purchasing Car Insurance");
                aptBean.setName("Joe D.Customer");
                aptBean.setTime("05:30 pm");
                 
                 
                //only serialized vector will be appointments
                Vector appointments = new Vector();
                Vector months = new Vector();
                Vector days = new Vector();
                 
                 
                //the key is this for loop: build vector structure adding
                //vectors, and finally adding the bean to each 'day' vectr
                for (int i = 0; i<12; i++) {
                    appointments.add(new Vector());
                    for(int j = 0; j<31; j++){
                        //appointments[i][j].add(new Vector());
                        ((Vector)appointments.elementAt(i)).add(new Vector());
                        for(int k = 0; k<5; k++){
                            months = ((Vector)appointments.elementAt(i));
                            days = (Vector)months.elementAt(j);
                            days.add(aptBean);//adding same bean every time!
                 
                        }
                    }
                 
                } //end of super fun nested for statement
                 
          
                 
                //now save these hard coded beans into the file specified.
                try {
                                //bool arg is to set append=true
                                FileOutputStream fos = new FileOutputStream(".\\appointments.dat");
                                ObjectOutputStream oos = new ObjectOutputStream(fos);
                                oos.writeObject(appointments);
                                oos.flush();
                                oos.close();
                                fos.close();
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
          
                 */
            }//end of 'run' method
        });
    }
    
    //HELPER methods
    //print
    public String printDate(Vector appointments, int month, int day) {
        
        if (day == 0) {
            System.out.println("something is wrong.");
            
        }
        
        String bigString = "";
        //System.out.println("currentmonth=" + month);
        Vector beansVector = ((Vector)((Vector)appointments.elementAt(--month)).elementAt(--day));
        for(int i = 0; i<beansVector.size(); i++) {
            
            AppointmentBean temp = (AppointmentBean)beansVector.elementAt(i);
            bigString = bigString + "APPOINTMENT ID:" + (i+1) + "\n" + temp.printString();
            
        }
         
                
                return bigString;
        
    }
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField agentField;
    private javax.swing.JScrollPane appointmentsPane;
    public javax.swing.JTextArea appointmentsText;
    private javax.swing.JButton backButton;
    private javax.swing.JButton backMonthButton;
    private javax.swing.JMenu barMenuA;
    private javax.swing.JTextArea bulletinBoardText;
    private javax.swing.JButton clearButton1;
    private javax.swing.JButton clearButton2;
    private javax.swing.JTextField deleteAppointmentField;
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton forwardButton;
    private javax.swing.JButton forwardMonthButton;
    private javax.swing.JMenuItem itemA1_1;
    private javax.swing.JMenuItem itemA1_2;
    private javax.swing.JMenuItem itemA2_1;
    private javax.swing.JMenuItem itemA2_2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel leftFooterPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTextField msgField;
    private javax.swing.JLabel msgLabel;
    private javax.swing.JTextField nameField;
    private javax.swing.JPanel navPanel;
    private javax.swing.JPanel onlyPanel;
    private javax.swing.JLabel panel1Label;
    private javax.swing.JLabel panel2Label;
    private javax.swing.JTextField reasonField;
    private javax.swing.JPanel rightFooterPanel;
    private javax.swing.JMenu subMenuA1;
    private javax.swing.JMenu subMenuA2;
    private javax.swing.JTextField subjectField;
    private javax.swing.JLabel subjectLabel;
    private javax.swing.JButton submitAptButton;
    private javax.swing.JButton submitMsgButton;
    private javax.swing.JTextField timeField;
    private javax.swing.JPanel topLeftPanel;
    private javax.swing.JPanel topRightPanel;
    // End of variables declaration//GEN-END:variables
    private static String[] MONTH_NAMES = {"January", "February", "March", "April", "May",
            "June", "July", "August", "September", "October",
            "November", "December"};
            private static int currentDay;
            private static int currentMonth;
            private Vector appointments;

            
}//end of dpf class
