I'm trying to make an application that stores, delete and view customer data.
As the subjects says, is there a way where I could enter data into a form and see it in the JTable, possibly as a new row to the table.
Such as, I have a JFrame object that opens a JDialog box. On the JDialog box there are two buttons to choose from, one that opens a form (on a JDialog) to enter new customer information and the other that opens a JDialog and shows a table of customers (using a JTable and my own implemented table model).
This is the code that I have for the customer table (including the Customer class that stores the data and my table model):
I've tried various tutorials (including Sun's) but didn't get much out of it.
If you understand the code you posted, you can see there is an addCustomer(Customer c) method in the CustomerTableModel class. What you need to do is to gather data from user in the EditCustomerDetailsDialogue class and create Customer object form that data. Then all you need to do is call the addCustomer method and pass that customer object. This smells like a home work assignment so I will not go into too much detail. If you have specific questions feel free to ask.
Joined: Mar 21, 2009
thanks for the reply,
so to clarify, each time an instance of JDialog that contains a form is opened, I would construct a Customer object and get the data from the data fields and assign them to the instance variables of the newly constructed Customer object? Then using this object as a parameter and pass it to the addCustomer(Customer c) method?
Here's a snippet of my 'to-be' code for the form on adding a new customer:
Would this be a valid and reasonable way to do it?
*EDIT* Okay, I know the question just asked sounds stupid. As a Java learning programmer I should test it out and not just rely on others experiences.
I'll test it out and post a result.
Joined: Mar 21, 2009
I have tried and have implemented the 'to do' code as posted earlier. It works!
Now, I'll have to go and firgure out how to edit the data... I'll probably write a method getCustomerAt() and override the setValueAt() method and then use one of the fire..() methods to update the table.