spencer.kindt 0 Newbie Poster

I have to make a bank GUI and I have a Jlist that populates with the customer objects (viewable by name) and I can view their individual info... but when I select the customer, I also want to be able to pull their account info and put it in a jtable that is on the same frame. I have a class to create a model for the table (I don't need that, but was trying to figure it out)... I got it to work to put in customer info, but I can't get it to put in account info... Can some one help me?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.byu.isys403.skindt.gui;

import javax.swing.table.*;
import edu.byu.isys403.cca.*;
import java.util.*;
/**
 *
 * @author Spence
 */
public class AcctModel extends AbstractTableModel {
    
    List<Account> acct = null;
    
    public AcctModel (List<Account> account){
        this.acct = account;
    }
    
     @Override
    public int getRowCount() {
        return acct.size();
    }

    /** Returns the number of columns */
    @Override
    public int getColumnCount() {
        return 3;
    }

    /** Returns the given cell value */
    @Override
    public Object getValueAt(int row, int col) {
        //Customer cust = (Customer)custs.values().toArray()[row];
        Customer selCustomer = (Customer)jList2.getSelectedValue();
        Account accts = (Account) acct.toArray()[row];
        if (col == 0){
            return accts.getAccountNumber();
        } else if (col == 1) {
            return accts.getAccountType();
        } else if (col == 2) {
            return accts.getBalance();
        }
        return "";
    }
    
    //change map to list
    
    public String getColumnName (int column){
        if (column == 0) {
            return "Account Number";
        } else if (column == 1) {
            return "Account Type";
        } else if (column == 2) {
            return "Balance";
        }
        return "";
    }
    
}
public class MainFrame extends javax.swing.JFrame {

    List<Customer> customers = new LinkedList<Customer>();
    List<Account> accounts = new LinkedList<Account>();
    //Map<String, Customer> customers = new TreeMap<String, Customer>();
    MyModel mm = new MyModel(customers);
    AcctModel nn = new AcctModel(accounts);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
    DefaultListModel dmCustList = new DefaultListModel();

    /** Creates new form MainFrame */
    public MainFrame() {
        
        try {
            initComponents();
            pop();
            
        //jTable2.setModel(mm);
        jTable2.setModel(nn);

            //dmCustList = new DefaultListModel();
            jList2.setModel(dmCustList);

            for (Customer c : customers) {
                dmCustList.addElement(c);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void pop() throws Exception {
        // Customer 1 and his accounts
        Customer c1 = new Customer();
        c1.setName("Bart Simpson");
        c1.setAddress("30 Maple Drive");
        c1.setCity("Springfield");
        c1.setState("Illinois");
        c1.setZipCode("51233");
        c1.setPhoneNum("801-333-1111");
        //customers.put(c1.getName(), c1);
        customers.add(c1);
        Account a1 = c1.createAccount();
        a1.setAccountType(Account.ACCOUNT_TYPE_CHECKING);
        a1.setAccountType(0);
        Account a2 = c1.createAccount();
        a2.setRate(0.05f);
        a2.setAccountType(Account.ACCOUNT_TYPE_SAVINGS);
        
        Customer c2 = new Customer();
        c2.setName("Cecil");
        c2.setAddress("123 BYU");
        c2.setCity("Provo");
        c2.setState("Utah");
        c2.setZipCode("84604");
        c2.setPhoneNum("801-911-1111");
        //customers.put(c1.getName(), c1);
        customers.add(c2);
        Account a3 = c2.createAccount();
        a3.setAccountType(Account.ACCOUNT_TYPE_CHECKING);
        a3.setAccountType(0);
        Account a4 = c2.createAccount();
        a4.setRate(0.05f);
        a4.setAccountType(Account.ACCOUNT_TYPE_SAVINGS);

        // post an initial balance
        Transaction tx1 = a1.createTransaction();
        tx1.setAmount(10.00);
        Calendar cal = Calendar.getInstance();
        cal.set(2008, 8, 13, 9, 13, 15);  // 2008-08-13 09:13:15
        tx1.setDate(cal.getTime());
        tx1.setMemo("Initial deposit");
        tx1.setTxType(Transaction.TX_TYPE_CREDIT);
        tx1.post();

        // withdraw
        Transaction tx2 = a1.createTransaction();
        tx2.setAmount(5.00);
        tx2.setDate(sdf.parse("2008.08.13 at 09:14:45 MDT"));
        tx2.setMemo("Standard withdrawal");
        tx2.setTxType(Transaction.TX_TYPE_DEBIT);
        tx2.post();

        // transfer money
        Transaction tx3 = a1.createTransaction();
        Transaction tx4 = a2.createTransaction();
        tx3.setAmount(1.00);
        tx3.setTxType(Transaction.TX_TYPE_DEBIT);
        tx3.setDate(new Date()); // now
        tx3.setMemo("Transfer to " + tx4.getId());
        tx4.setAmount(1.00);
        tx4.setTxType(Transaction.TX_TYPE_CREDIT);  // tx4 date is auto set
        tx4.setMemo("Transfer from " + tx3.getId());
        tx3.post();
        tx4.post();

        // to fulfill the requirements of the assignment, I now need to
        // creat a second customer, with accounts and transactions

    }//run

    /** 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">
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel6 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jButton13 = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jButton10 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jPanel8 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jScrollPane3 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jPanel10 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("System Actions"));

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

        jButton9.setText("jButton9");
        jPanel6.add(jButton9);

        getContentPane().add(jPanel6, java.awt.BorderLayout.PAGE_END);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Customers"));
        jPanel1.setLayout(new java.awt.BorderLayout());

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

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

        jButton6.setText("Delete");
        jPanel7.add(jButton6);

        jPanel1.add(jPanel7, java.awt.BorderLayout.SOUTH);

        jTable2.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"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER);

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

        jScrollPane4.setViewportView(jList2);

        jPanel9.add(jScrollPane4);

        jButton13.setText("View");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });
        jPanel9.add(jButton13);

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder("Actions"));
        jPanel11.setLayout(new java.awt.GridLayout(7, 2, 9, 9));

        jLabel1.setText("Name:");
        jPanel11.add(jLabel1);

        jTextField1.setText("jTextField1");
        jPanel11.add(jTextField1);

        jLabel2.setText("Address:");
        jPanel11.add(jLabel2);

        jTextField2.setText("jTextField2");
        jPanel11.add(jTextField2);

        jLabel3.setText("City:");
        jPanel11.add(jLabel3);

        jTextField3.setText("jTextField3");
        jPanel11.add(jTextField3);

        jLabel4.setText("State:");
        jPanel11.add(jLabel4);

        jTextField4.setText("jTextField4");
        jPanel11.add(jTextField4);

        jLabel5.setText("Zip Code:");
        jPanel11.add(jLabel5);

        jTextField5.setText("jTextField5");
        jPanel11.add(jTextField5);

        jLabel6.setText("Phone: (i.e. 555-555-5555)");
        jPanel11.add(jLabel6);

        jTextField6.setText("jTextField6");
        jPanel11.add(jTextField6);

        jButton10.setText("Save");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel11.add(jButton10);

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

        jPanel9.add(jPanel11);

        jPanel1.add(jPanel9, java.awt.BorderLayout.PAGE_START);

        jTabbedPane1.addTab("Customers", jPanel1);

        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Account Actions"));

        jButton1.setText("View");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel5.add(jButton1);

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

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

        jPanel2.add(jPanel5, java.awt.BorderLayout.PAGE_END);

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("test"));
        jPanel8.setLayout(new java.awt.BorderLayout());

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel8.add(jComboBox1, java.awt.BorderLayout.PAGE_START);

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane3.setViewportView(jList1);

        jPanel8.add(jScrollPane3, java.awt.BorderLayout.CENTER);

        jPanel2.add(jPanel8, java.awt.BorderLayout.CENTER);

        jPanel10.setLayout(new java.awt.GridLayout());

        jTable3.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"
            }
        ));
        jScrollPane5.setViewportView(jTable3);

        jPanel10.add(jScrollPane5);

        jPanel2.add(jPanel10, java.awt.BorderLayout.NORTH);

        jTabbedPane1.addTab("Accounts", jPanel2);

        jPanel3.setLayout(new java.awt.BorderLayout());

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Transaction Actions"));

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

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

        jPanel3.add(jPanel4, java.awt.BorderLayout.PAGE_END);

        jTable1.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"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jTabbedPane1.addTab("Transactions", jPanel3);

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

    System.exit(0);
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

    try {
        Customer c2 = new Customer();
        c2.setName("Lisa Simpson");
        c2.setAddress("30 Maple Drive");
        c2.setCity("Springfield");
        c2.setState("Illinois");
        c2.setZipCode("51233");
        c2.setPhoneNum("801-333-1111");
        customers.add(c2);
        Account a1 = c2.createAccount();
        a1.setAccountType(Account.ACCOUNT_TYPE_CHECKING);
        a1.setAccountType(0);
        Account a2 = c2.createAccount();
        a2.setRate(0.05f);
        a2.setAccountType(Account.ACCOUNT_TYPE_SAVINGS);
        System.out.println("Lisa is edited"); //make sure that LISA is added
        mm.fireTableDataChanged();
    } catch (Exception exception) {
    }
// TODO add your handling code here:

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.