import javax.swing.table.*; public class AddressData extends AbstractTableModel { public static final String COLS[] = {"Name", "Email"}; private AddressBook book = new AddressBook(); private boolean isDirty = false; public AddressData() { isDirty = false; } public int getColumnCount() { return COLS.length; } public int getRowCount() { return book.getSize(); } public String getColumnName(int col) { return COLS[col]; } public Object getValueAt(int row, int col) { Address a = book.getAddress(row); if (col == 0) return a.getName(); else return a.getEmail(); } public void setValueAt(Object obj, int row, int col) { Address a = book.getAddress(row); if (col == 0) a.setName(obj.toString()); else a.setEmail(obj.toString()); fireTableRowsUpdated(row, row); isDirty = true; } public boolean isCellEditable(int row, int col) { return true; } public void add(Address a) { book.addAddress(a); fireTableRowsInserted(book.getSize()-1, book.getSize()-1); isDirty = true; } public void delete(int row) { book.delAddress(row); fireTableRowsDeleted(row, row); isDirty = true; } public boolean isDirty() { return isDirty; } }