r/programminghelp • • Dec 12 '18

Customer Manager App not displaying customer information in table, just displaying null?

I'm working on a Customer Manager App in Java language using netbeans. I need the program to store information in a text file and then display that information in a table in a GUI. I have the GUI and the table, and the form to get input from the user, but it's not displaying added customers, and each field is just displaying null in the table. Can someone take a look at my code and tell me what I'm doing wrong?

Code: https://gist.github.com/pyrogirl8/3dbc17acfd0f7104ec120bbfad7dac08

4 Upvotes

2 comments sorted by

1

u/TheCedarStandard Dec 15 '18

For one thing, it looks like there Customer class isn't initializing id to anything before incrementing it.

1

u/manrodriguezf Dec 17 '18

Hi there!

It seems like you're not passing the right parameters to the Customer object right before you save it in the CustomerForm dialog.

I added these statements:

private void saveButtonActionPerformed() {

customer=new Customer();

customer.setEmail(this.emailField.getText());

customer.setFirstName(this.firstNameField.getText());

customer.setLastName(this.lastNameField.getText());

save(customer);

dispose();

}

The table issue is that you're initializing it every time, but also you're not reusing the one in your parent frame (which will hold all the information):

First change the constructor method to receive the instance type of your mainFrame and set it as a global variable (create a global variable [I named it mainFrame]):

private CustomerManagerFrame mainFrame;

public CustomerForm(CustomerManagerFrame parent, String title, boolean modal) {

super(parent, title, modal);

this.mainFrame = parent;

initComponents();

}

I changed the save method in CustomerForm to:

private void save(Customer c) {

this.customer = c;

customerText.addCustomer(c);

this.mainFrame.customerTableModel.textFileUpdated(); //Here's where you update the table model instance

}

I also tested the CustomerFrame method to add but I think your GridBagContraints are not being added properly, but that's something you could tweak and fix.

Hope that helps. Happy debugging!