Question: JAVA PROGRAM - GUI - error checking needed to be added to the program The program is complete however please add error checking for when

JAVA PROGRAM - GUI - error checking needed to be added to the program

The program is complete however please add error checking for when you are adding a person or editing a Person. Please add so that in the joption pane dialog you can hit CANCEL or the X button and it will return you to the main program .

Would not let me upload a file so here are the classes. Thank you!

////// START ADDRESS BOOK CLASS ////////

package addressBook;

import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.FileInputStream; import java.util.Scanner; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame;

public class AddressBook { private static ArrayList people; public static void main(String[] args) { if(SerializableRead()){ System.out.println("File is already written."); } else { people = new ArrayList(); Person Carlos = new Person ("Carlos","Eduardo","Lopez", "Job Friend","Work",new telephone("407-440-7048","Cell"),new address("9981 CharlesnDr","Orlando","fl","orange","32222","Home") ,new email("Personal", "cLopez@Email.com")); Carlos.getAddress().add(new address("123 Car Dr","Orlando","fl","orange","32832","Buisness")); Carlos.getTelephoneNums().add(new telephone("321-303-7444","Home")); Carlos.getEmails().add(new email("Buisness","Lopez@Email.com")); Person Jimmy = new Person ("Jimmy","Eddie","Clan","Job Friend","Work", new telephone("407-888-5888","Cell"),new address("123 Tree way Dr","Orlando","fl","orange","32832","Home") ,new email("Personal","ClanJ@Email.com")); Jimmy.getAddress().add(new address("345 Leafy Way Dr","Orlando","fl","Orange","34233","Buisness")); Jimmy.getTelephoneNums().add(new telephone("321-303-7556","Home")); Jimmy.getEmails().add(new email("Buisness","Clan@Email.com")); Person John = new Person ("John","Bee","Lang","ClassMate","School",new telephone("407-111-5888","Cell"),new address("321 flower Dr","Orlando","fl","orange","32832","Home") ,new email("Personal","Bee@Email.com")); John.getAddress().add(new address("111 Valencia Way Dr","Orlando","fl","Orange","34444","Buisness")); John.getTelephoneNums().add(new telephone("321-333-7556","Home")); John.getEmails().add(new email("Buisness","John@Email.com")); Person Dora = new Person ("Dora","Elia","Cats", new telephone("407-099-5888","Work"),new address("321 Dandelion Dr","Orlando","fl","orange","32832","Home") ,"Worker","Friend",new email("Personal","Catlove@Email.com")); Person Luis = new Person ("Luis","Albert","Silver", new telephone("407-888-5888","Work"),new address("321 landstar Dr","Orlando","fl","Osceola","32832","Home") ,"Work","Friend",new email("Personal","Silver@Email.com")); Person Ken = new Person ("Ken","Lam","Nuygen", new telephone("407-855-5888","Cell"),new address("321 Oaktree Dr","Kissimee","fl","Osceola","32833","Home") ,"Travel Friend","Tall",new email("Buisness","Nuygen@Email.com")); Person Bill = new Person ("Bill","Wild","Smith", new telephone("407-855-5458","Cell"),new address(" 444 Winteroaks ln","Miami","fl","Osceola","32043","Home") ,"Buisness","Short",new email("Personal","Smith25@Email.com")); Person Troy = new Person ("Troy","Antohny","Mealey", new telephone("407-242-1794","Home"),new address(" 5 1st ct","Windermere","fl","Green","34786","Buisness") ,"Friend","Fun Friend",new email("Buisness","HelloimTroy@Email.com")); Person Dane = new Person ("Dane","Chris","Shafatt", new telephone("407-255-1794","Home"),new address(" 5 1st ct","Windermere","fl","Green","34786","Home") ,"Friend","Troy Brother",new email ("Personal","123@yahoo.com")); Person Kelly = new Person ("Kelly","Susan","Klark", new telephone("407-256-1794","Cell"),new address(" 444 Temple ct","WinterPark","fl","Orange","34786","Home") ,"Friend","Troy Sister",new email ("Personal","Kelly@EMAIL.com"));

people.add(Carlos); people.add(Jimmy); people.add(John); people.add(Dora); people.add(Luis); people.add(Ken); people.add(Bill); people.add(Troy); people.add(Dane); people.add(Kelly); //people.remove(6); } final JTableSorting frame = new JTableSorting(people); frame.show(); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent event) { SerializableWrite(frame.getList()); frame.dispose(); System.exit(0); } }); SerializableWrite(frame.getList()); }//end of main

public static void SerializableWrite(List people) { ObjectOutputStream out; try { out = new ObjectOutputStream(new FileOutputStream("database.dat")); out.writeObject(people); } catch(Exception ex) { System.out.println("The error: " + ex.getMessage()); } } @SuppressWarnings("unchecked") public static boolean SerializableRead() { ObjectInputStream in; try { in = new ObjectInputStream(new FileInputStream("database.dat")); people = (ArrayList)(in.readObject()); //for(Person p: people) { // System.out.println(p); //} } catch (FileNotFoundException fnfe) { return false; } catch (Exception ex) { System.out.println("The error: " + ex.getMessage()); System.out.println("Data was corrupted. Please do something..."); return false; } return true; } }// END OF ADDRESS BOOK CLASS

////////// START OF PERSON CLASS /////////////

package addressBook;

import java.io.Serializable;

import java.util.ArrayList;

public class Person implements Serializable {

private static final long serialVersionUID = 1L;

private int index;

private String firstName;

private String lastName;

private String middleName = "";

private String note= "";

private String group= "";

private ArrayList emails;// Array list that holds emails

private ArrayList

addr; // array list that holds address objects

private ArrayList telephoneNums;//array list that holds telephone objects

public Person(String firstName, String middleName, String lastName, String note,String group,telephone telephoneNum, address address,email emails) {

this.firstName = firstName;

this.lastName = lastName;

this.middleName = middleName;

this.note = note;

this.group=group;

this.emails=new ArrayList();

this.emails.add(emails);

this.addr = new ArrayList

();

this.addr.add(address);

this.telephoneNums = new ArrayList();

this.telephoneNums.add(telephoneNum);

}

public Person(String firstName, String lastName,address address,telephone telephoneNum) {

this.firstName = firstName;

this.lastName = lastName;

this.addr = new ArrayList

();

this.addr.add(address);

this.telephoneNums = new ArrayList();

this.telephoneNums.add(telephoneNum);

}// constructor First and last name, address. note, telNum,

public Person(String firstName, String lastName,ArrayList

address,telephone telephoneNum, ArrayList emails) {

this.firstName = firstName;

this.lastName = lastName;

this.addr = address;

this.telephoneNums = new ArrayList();

this.telephoneNums.add(telephoneNum);

this.emails = emails;

}// constructor First and last name, address. note, telNum,

public Person(String firstName,String middleName,String lastName,String note,String group, ArrayList

address,ArrayList telephone, ArrayList emails) {

this.firstName = firstName;

this.lastName = lastName;

this.note = note;

this.group = group;

this.middleName= middleName;

this.addr = address;

this.telephoneNums = telephone;

this.emails = emails;

}// constructor First and last name, address. note, telNum,

public Person(String firstName, String lastName,String middleName,String note,String group) {

this.firstName = firstName;

this.lastName = lastName;

this.middleName = middleName;

this.note = note;

this.group=group;

}// constructor First and last name

public Person(String firstName,String middleName, String lastName,telephone telephoneNum, address address,String group ,

String note, email emails) {

this.firstName = firstName;

this.middleName = middleName;

this.lastName = lastName;

this.group = group;

this.note = note;

this.emails=new ArrayList();

this.emails.add(emails);

this.addr = new ArrayList

();

this.addr.add(address);

this.telephoneNums = new ArrayList();

this.telephoneNums.add(telephoneNum);

}// constructor

public int getIndex() {

return index;

}

public void setIndex(int index) {

this.index = index;

}

public ArrayList getTelephoneNums() {

return telephoneNums;

}

public void setTelephoneNums(ArrayList telephoneNums) {

this.telephoneNums = telephoneNums;

}

public ArrayList getEmails() {

return emails;

}

public void setemails(ArrayList emails) {

this.emails = emails;

}

public ArrayList

getAddress() {

return addr;

}

public void setAddress(ArrayList

address) {

this.addr = address;

}

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public String getMiddleName() {

return middleName;

}

public void setMiddleName(String middleName) {

this.middleName = middleName;

}

public String getNote() {

return note;

}

public void setNote(String note) {

this.note = note;

}

public String getGroup() {

return group;

}

public void setGroup(String group) {

this.group = group;

}

@Override

public String toString() {

String result = " Person: " + firstName +" "+ middleName + " " + lastName ;

for(address addr : addr)

{

result += addr;

}

for(telephone tel : telephoneNums)

{

result += tel;

}

for(email email : emails)

{

result += email;

}

result += " Group:"+group+" Note:"+ note+" ";

return result;

}

}// END OF PERSON CLASS

/// START OF ADDRESS CLASS ///////

package addressBook;

import java.io.Serializable;

public class address implements Serializable {

private static final long serialVersionUID = 1L;

private String streetName;

private String city;

private String state;

private String county;

private String postalCode;

private String addressType;

public address(String streetName, String city, String state, String county, String postalCode,String addressType) {

super();

this.addressType=addressType;

this.streetName = streetName;

this.city = city;

this.state = state;

this.county = county;

this.postalCode = postalCode;

}// Constructor for address

public String getStreetName() {

return streetName;

}

public void setStreetName(String streetName) {

this.streetName = streetName;

}

public String getCity() {

return city;

}

public void setCity(String city) {

this.city = city;

}

public String getState() {

return state;

}

public void setState(String state) {

this.state = state;

}

public String getCounty() {

return county;

}

public void setCounty(String county) {

this.county = county;

}

public String getPostalCode() {

return postalCode;

}

public void setPostalCode(String postalCode) {

this.postalCode = postalCode;

}

public String getAddressType() {

return addressType;

}

public void setAddressType(String addressType) {

this.addressType = addressType;

}

@Override

public String toString() {

return " "+addressType + " Address: "+ streetName +","+ city +" ,"+ state +"," + postalCode +", "+ county +" County";

}

}/// END OF ADDRESS CLASS

/////// START OF EMAIL CLASS /////////

package addressBook;

import java.io.Serializable;

public class email implements Serializable {

private static final long serialVersionUID = 1L;

private String emailType;

private String emails;

public email(String emailType, String emails) {

super();

this.emailType = emailType;

this.emails = emails;

}

public String getEmailType() {

return emailType;

}

public void setEmailType(String emailType) {

this.emailType = emailType;

}

public String getEmail() {

return emails;

}

public void setEmail(String emails) {

this.emails = emails;

}

@Override

public String toString() {

return " "+emailType+" Email: " + emails +"";

}

}/// END OF EMAIL CLASS

/////// START OF TELEPHONE CLASS //////////

package addressBook;

import java.io.Serializable;

public class telephone implements Serializable {

private static final long serialVersionUID = 1L;

private String telephoneNums;

private String telephoneType;

public telephone(String telephoneNums,String telephoneType) {

super();

this.telephoneNums = telephoneNums;

this.telephoneType = telephoneType;

}

public String getTelephoneNums() {

return telephoneNums;

}

public void setTelephoneNums(String telephoneNums) {

this.telephoneNums = telephoneNums;

}

public String getTelephoneType() {

return telephoneType;

}

public void setTelephoneType(String telephoneType) {

this.telephoneType = telephoneType;

}

@Override

public String toString() {

return " "+telephoneType+" Number " + telephoneNums + "";

}

}// END OF TELEPHONE CLASS

///// START OF JTABLESORTING CLASS ////////

package addressBook;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.util.List;

import javax.swing.*;

public class JTableSorting extends JFrame {

private static final long serialVersionUID = 1L;

private JTable table;

private personTableModel model;

public JTableSorting(final ArrayList people){

super("Address Book ");

model = new personTableModel(people);

table = new JTable(model);

////////////////////////////////////////////////////////////////

table.addMouseListener(new MouseAdapter(){

public void mouseClicked(MouseEvent event){

if (event.getClickCount()==1){

JTable target = (JTable)event.getSource();

int row = target.getSelectedRow();

row = table.convertRowIndexToModel(row);

int column = target.getSelectedColumn();

int result = JOptionPane.showOptionDialog(null,people.get(row), "Information", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "OK", "Edit", "Delete"}, null);

if (result == JOptionPane.CANCEL_OPTION) {

System.out.println("Delete");

model.deletePerson(row);

} else if (result == JOptionPane.NO_OPTION) {

System.out.println("Edit");

editPerson(row);

}

}

}

});

////////////////////// Add Contact button creation and action //////////////////////////////////////////

table.setAutoCreateRowSorter(true);

add(new JScrollPane(table),BorderLayout.CENTER);

JButton button = new JButton("Add Contact");

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

String firstName;

String lastName;

String middleName = "";

String note= "";

String group= "";

// Email Information //

String emailType;

String email;

///////////////////////////

////Telephone Number info ////

String telephoneNums;

String telephoneType;

///////////////////////////

////Address Information ////

String streetName;

String city;

String state;

String county;

String postalCode;

String addressType;

///////////////////////////

firstName = JOptionPane.showInputDialog(null, "What is the First name?");

middleName= JOptionPane.showInputDialog(null, "What is the Middle name?");

lastName = JOptionPane.showInputDialog(null, "What is the Last name?");

note = JOptionPane.showInputDialog(null, "What note would you like to write for this Person?");

group = JOptionPane.showInputDialog(null, "What group is this person calssified in?");

char conti = 0;

ArrayList emails = new ArrayList();

do {

email = JOptionPane.showInputDialog(null, "What is this persons email ?");

emailType = JOptionPane.showInputDialog(null, "Is this a Personal or Buisness email?");

email lastEmail = new email(email,emailType);

emails.add(lastEmail);

String vall = JOptionPane.showInputDialog(null, "Would you like to enter another email? (Yes, No");

if(vall!=null && !vall.isEmpty()){

conti = vall.charAt(0);

conti = Character.toUpperCase(conti);

}

} while (conti == 'Y');

char cont = 0;

ArrayList

addresses = new ArrayList
();

do {

addressType = JOptionPane.showInputDialog(null, "What Type of address is this going to be? (Home, Buisness");

streetName = JOptionPane.showInputDialog(null, "What is the name of the Street");

city = JOptionPane.showInputDialog(null, "What is the name of the city ? ");

state = JOptionPane.showInputDialog(null, "What is the name of the state?");

county = JOptionPane.showInputDialog(null, "What is the name of the county ?");

postalCode = JOptionPane.showInputDialog(null, "what is the postal code ?");

address lastAddress = new address(streetName,city,state,county,postalCode,addressType);// Creating a new address object and filling it with the info we gathered

addresses.add(lastAddress); // Adding the new address to the array list

String vall = JOptionPane.showInputDialog(null, "Would you like to enter another Address? (Yes , No");

if(vall!=null && !vall.isEmpty()){

cont = vall.charAt(0);

cont = Character.toUpperCase(cont);

}

/*cont = JOptionPane.showInputDialog(null, "Would you like to enter another Address? (Yes , No").charAt(0);

cont = Character.toUpperCase(cont);*/

} while (cont == 'Y');

char contr = 0;

ArrayList telephones = new ArrayList();

do {

telephoneNums = JOptionPane.showInputDialog(null, "What is this persons Telephone Number?");

telephoneType = JOptionPane.showInputDialog(null, "What type of number is this? (Home, Work, Cell)");

telephone lastTelephone = new telephone (telephoneNums,telephoneType);

telephones.add(lastTelephone);

String vall = JOptionPane.showInputDialog(null, "Would you like to enter another Telephone number? (Yes , No");

if(vall!=null && !vall.isEmpty()){

contr = vall.charAt(0);

contr = Character.toUpperCase(contr);

}

/*contr = JOptionPane.showInputDialog(null, "Would you like to enter another Telephone number? (Yes , No").charAt(0);

contr = Character.toUpperCase(contr);*/

} while (contr == 'Y');

if(!firstName.isEmpty() && !lastName.isEmpty() && !city.isEmpty() && !group.isEmpty()){

Person lastPerson = new Person (firstName,middleName,lastName,note,group,addresses,telephones, emails);

model.addPerson(lastPerson);

}else{

JOptionPane.showMessageDialog(null, "Details are empty. Unable to add contact! Please try again");

}

}

});

add(button, BorderLayout.SOUTH);

pack();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

}

private void editPerson(int row) {

String firstName;

String lastName;

String middleName = "";

String note= "";

String group= "";

// Email Information //

String emailType;

String email;

///////////////////////////

////Telephone Number Info ////

String telephoneNums;

String telephoneType;

///////////////////////////

////Address Information ////

String streetName;

String city;

String state;

String county;

String postalCode;

String addressType;

///////////////////////////

Person oldPerson = model.getList().get(row);

firstName = JOptionPane.showInputDialog(null, "What is the First name?", oldPerson.getFirstName());

middleName= JOptionPane.showInputDialog(null, "What is the Middle name?", oldPerson.getMiddleName());

lastName = JOptionPane.showInputDialog(null, "What is the Last name?", oldPerson.getLastName());

note = JOptionPane.showInputDialog(null, "What note would you like to write for this Person?", oldPerson.getNote());

group = JOptionPane.showInputDialog(null, "What group is this person calssified in?", oldPerson.getGroup());

// Edit all emails

ArrayList allEmails = oldPerson.getEmails();

ArrayList emails = new ArrayList();

for(email Email : allEmails){

email = JOptionPane.showInputDialog(null, "What is this persons email?", Email.getEmail());

emailType = JOptionPane.showInputDialog(null,"Is this a Personal or Buisness Email?", Email.getEmailType());

email lastEmail = new email(email, emailType);

emails.add(lastEmail);

}

char conti = 0;

String vall = JOptionPane.showInputDialog(null, "Would you like to enter another email? (yes,No)");

if(vall!=null && !vall.isEmpty()){

conti = vall.charAt(0);

conti = Character.toUpperCase(conti);

}

//conti = .charAt(0);

//conti = Character.toUpperCase(conti);

while (conti == 'Y') {

email = JOptionPane.showInputDialog(null, "What is this persons email?");

emailType = JOptionPane.showInputDialog(null,"Is this a Personal or Buisness Email?");

email lastEmail = new email(email, emailType);

emails.add(lastEmail);

vall = JOptionPane.showInputDialog(null, "Would you like to enter another email? (yes,No)");

if(vall!=null && !vall.isEmpty()){

conti = vall.charAt(0);

conti = Character.toUpperCase(conti);

}

/*conti = JOptionPane.showInputDialog(null, "Would you like to enter another email? (yes, No)").charAt(0);

conti = Character.toUpperCase(conti);*/

}

//Edit all addresses

ArrayList

allAddress = oldPerson.getAddress();

ArrayList

addresses = new ArrayList
();

for(address Address : allAddress){

addressType = JOptionPane.showInputDialog(null, "What Type of address is this going to be? (Home, Buisness)", Address.getAddressType());

streetName = JOptionPane.showInputDialog(null, "What is the name of the Street", Address.getStreetName());

city = JOptionPane.showInputDialog(null, "What is the name of the city ? ", Address.getCity());

state = JOptionPane.showInputDialog(null, "What is the name of the state?", Address.getState());

county = JOptionPane.showInputDialog(null, "What is the name of the county ?", Address.getCounty());

postalCode = JOptionPane.showInputDialog(null, "what is the postal code ?", Address.getPostalCode());

address lastAddress = new address(streetName,city,state,county,postalCode,addressType);

addresses.add(lastAddress);

}

char cont = 0;

vall = JOptionPane.showInputDialog(null, "Would you like to enter another Address? (Yes , No");

if(vall!=null && !vall.isEmpty()){

cont = vall.charAt(0);

cont = Character.toUpperCase(cont);

}

/*cont = JOptionPane.showInputDialog(null, "Would you like to enter another Address? (Yes , No").charAt(0);

cont = Character.toUpperCase(cont);

*/

while (cont == 'Y') {

addressType = JOptionPane.showInputDialog(null, "What Type of address is this going to be? (Home, Buisness)");

streetName = JOptionPane.showInputDialog(null, "What is the name of the Street");

city = JOptionPane.showInputDialog(null, "What is the name of the city ? ");

state = JOptionPane.showInputDialog(null, "What is the name of the state?");

county = JOptionPane.showInputDialog(null, "What is the name of the county ?");

postalCode = JOptionPane.showInputDialog(null, "what is the postal code ?");

address lastAddress = new address(streetName,city,state,county,postalCode,addressType);

addresses.add(lastAddress);

vall = JOptionPane.showInputDialog(null, "Would you like to enter another Address? (Yes , No");

if(vall!=null && !vall.isEmpty()){

cont = vall.charAt(0);

cont = Character.toUpperCase(cont);

}

/*cont = JOptionPane.showInputDialog(null, "Would you like to enter another Address? (Yes , No").charAt(0);

cont = Character.toUpperCase(cont);*/

}

// Edit telephone numbers

ArrayList allTelephoneNums = oldPerson.getTelephoneNums();

ArrayList telephones = new ArrayList();

for(telephone Telephone : allTelephoneNums){

telephoneNums = JOptionPane.showInputDialog(null, "What is this persons Tel Number?", Telephone.getTelephoneNums());

telephoneType = JOptionPane.showInputDialog(null, "What type of number is this? (Home, Work, Cell", Telephone.getTelephoneType());

telephone lastTele = new telephone(telephoneNums, telephoneType);

telephones.add(lastTele);

}

char contr = 0;

vall = JOptionPane.showInputDialog(null, "Would you like to enter another Telephone number? (Yes , No");

if(vall!=null && !vall.isEmpty()){

contr = vall.charAt(0);

contr = Character.toUpperCase(contr);

}

/*contr = JOptionPane.showInputDialog(null, "Would you like to enter another Telephone number? (Yes , No").charAt(0);

contr = Character.toUpperCase(contr);*/

while (contr == 'Y') {

telephoneNums = JOptionPane.showInputDialog(null, "What is this persons Tel Number?");

telephoneType = JOptionPane.showInputDialog(null, "What type of number is this? (Home, Work, Cell");

telephone lastTele = new telephone(telephoneNums, telephoneType);

telephones.add(lastTele);

vall = JOptionPane.showInputDialog(null, "Would you like to enter another Telephone number? (Yes , No");

if(vall!=null && !vall.isEmpty()){

contr = vall.charAt(0);

contr = Character.toUpperCase(contr);

}

/*contr = JOptionPane.showInputDialog(null, "Would you like to enter another Telephone number? (Yes , No").charAt(0);

contr = Character.toUpperCase(contr);

*/

}

if(!firstName.isEmpty() && !lastName.isEmpty() && !group.isEmpty()){

Person lastPerson = new Person (firstName,middleName,lastName,note,group,addresses,telephones, emails);

model.editPerson(lastPerson, row);

}else{

JOptionPane.showMessageDialog(null, "Details are empty. Unable to edit contact! Please try again");

}

}

public List getList() {

return model.getList();

}

}///////// END OF JTABLE SORTING CLASS /////////////////////

///////////// START OF PERSON TABLE MODEL CLASS ///////////////

package addressBook;

import javax.swing.table.*; import java.util.*;

public class personTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; private static final int COLUMN_NO = 0; private static final int COLUMN_FNAME = 1; private static final int COLUMN_LNAME = 2; private static final int COLUMN_CITY = 3; private static final int COLUMN_GROUP = 4; private String[] columnNames = {"NO.", "First Name", "Last Name", "City", "Group"}; private ListlistPeople; public personTableModel (ListlistPeople){ this.listPeople = listPeople; int indexCount = 1; for(Person Person:listPeople ){ Person.setIndex(indexCount++); } } @Override public int getColumnCount() { // TODO Auto-generated method stub return columnNames.length; }

@Override public int getRowCount() { // TODO Auto-generated method stub return listPeople.size(); } @Override public Object getValueAt(int rowIndex, int columnIndex) { Person Person = listPeople.get(rowIndex); Object retVal = null ; switch (columnIndex){ case COLUMN_NO: retVal = Person.getIndex(); break; case COLUMN_FNAME: retVal = Person.getFirstName(); break; case COLUMN_LNAME: retVal = Person.getLastName(); break; case COLUMN_CITY : retVal = Person.getAddress().get(0).getCity(); break; case COLUMN_GROUP : retVal = Person.getGroup(); break; default: throw new IllegalArgumentException("Invalid Column index"); }// end of switch return retVal; }// end of Get value at @Override public String getColumnName(int columnIndex){ return columnNames[columnIndex]; } @Override public Class getColumnClass(int columnIndex){ if(listPeople.isEmpty())return Object.class; else return getValueAt(0,columnIndex).getClass(); } @Override public void setValueAt(Object value, int rowIndex, int columnIndex){ Person Person = listPeople.get(rowIndex); if(columnIndex == COLUMN_NO){ Person.setIndex((int)value); } } public String[] getColumnNames(){ return columnNames; } public void addPerson(Person person){

person.setIndex(listPeople.size()+1); listPeople.add(person); this.fireTableDataChanged(); } public void deletePerson(int row){

listPeople.remove(row); this.fireTableDataChanged(); }

public List getList() { // TODO Auto-generated method stub return listPeople; }

public void editPerson(Person lastPerson, int row) { lastPerson.setIndex(row+1); listPeople.set(row, lastPerson); this.fireTableDataChanged(); } }// END OF PERSON TABLE MODEL CLASS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!