Please take time to read the code disclaimer.

<--Go back to Kent's Projects

<--Go back to project post

/**
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * TransactionDetails.java
 *
 * Created on Oct 7, 2011, 1:54:53 AM
 */
package edu.byu.isys403.katsuru.bankobjects;

import java.awt.Toolkit;

/**
 *
 * @author Kent
 */
public class TransactionDetails extends javax.swing.JFrame {

  private Account account;

  /** Creates new form TransactionDetails
   * 
   */
  public TransactionDetails() {
    initComponents();
  }

public TransactionDetails(Account account) {
    initComponents();
    this.account = account;
    TransactionTableModel transactionTableModel = new TransactionTableModel(account.getTransactionsList());
    Table.setModel(transactionTableModel);
    int y = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2) - this.getHeight() / 2;
    int x = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2) - this.getWidth() / 2;
    this.setLocation(x, y);
  }

  /** 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")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        TablePanel = new javax.swing.JPanel();
        TablePane = new javax.swing.JScrollPane();
        Table = new javax.swing.JTable();
        BottomPanel = new javax.swing.JPanel();
        AddTransactionButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Transaction history for this account.");
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));

        TablePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Transactions"));
        TablePanel.setLayout(new java.awt.BorderLayout());

        Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TablePane.setViewportView(Table);

        TablePanel.add(TablePane, java.awt.BorderLayout.CENTER);

        getContentPane().add(TablePanel);

        BottomPanel.setLayout(new javax.swing.BoxLayout(BottomPanel, javax.swing.BoxLayout.LINE_AXIS));

        AddTransactionButton.setText("Add Transaction");
        AddTransactionButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                AddTransactionButtonMouseClicked(evt);
            }
        });
        BottomPanel.add(AddTransactionButton);

        getContentPane().add(BottomPanel);

        pack();
    }// //GEN-END:initComponents

  private void AddTransactionButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddTransactionButtonMouseClicked
    NewTransactionDialog newTransactionDialog = new NewTransactionDialog(this, true);
    newTransactionDialog.setVisible(true);
    if (newTransactionDialog.isSubmitted()) {
      boolean newType = newTransactionDialog.getType();
      double newAmount = newTransactionDialog.getAmount();
      String newDescription = newTransactionDialog.getDescription();
      Transaction newTransaction = new Transaction (account, newType, newAmount, newDescription, account.transactionMemo(newType, account.getCustomer(), account, null));
      account.addTransaction(newTransaction);
//      Table.revalidate();
      System.out.println(account.getBalance());
      ((TransactionTableModel)Table.getModel()).fireTable();
    }
  }//GEN-LAST:event_AddTransactionButtonMouseClicked

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    /** Set the Nimbus look and feel */
    //
        /** 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(TransactionDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
      java.util.logging.Logger.getLogger(TransactionDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      java.util.logging.Logger.getLogger(TransactionDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(TransactionDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //

    /** Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {

      public void run() {
        new TransactionDetails().setVisible(true);
      }
    });
  }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddTransactionButton;
    private javax.swing.JPanel BottomPanel;
    private javax.swing.JTable Table;
    private javax.swing.JScrollPane TablePane;
    private javax.swing.JPanel TablePanel;
    // End of variables declaration//GEN-END:variables
}