FileDocCategorySizeDatePackage
AccountTableModel.javaAPI DocExample1245Thu Jun 27 19:20:22 BST 2002com.oreilly.mock

AccountTableModel.java

package com.oreilly.mock;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.List;

public class AccountTableModel extends AbstractTableModel {
    public static final int ACCT_TYPE_COL = 0;
    public static final int ACCT_BALANCE_COL = 1;
    public static final int ACCT_NUMBER_COL = 2;

    private List accounts = new ArrayList();

    public int getRowCount() {
        return this.accounts.size();
    }

    public int getColumnCount() {
        return 3;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Account acct = (Account) this.accounts.get(rowIndex);
        switch (columnIndex) {
            case ACCT_BALANCE_COL:
                return new Double(acct.getBalance());
            case ACCT_NUMBER_COL:
                return acct.getAccountNumber();
            case ACCT_TYPE_COL:
                return new Integer(acct.getAccountType());
        }
        throw new IllegalArgumentException("Illegal column: "
                + columnIndex);
    }

    public void addAccount(Account acct) {
        int row = this.accounts.size();
        this.accounts.add(acct);
        fireTableRowsInserted(row, row);
    }
}