Listen for changes in a custom Object?
Hi, I have a class called Order, and this is a very simple example:
Code:
public class Order {
List<Product> orderList;
Order() {
orderList = new ArrayList<Product>();
}
public void addProduct(Product p) { orderList.add(p); }
}
I create an instance of the class like this:
Code:
Order currentOrder = new Order();
Then I have a GUI to edit the order, add products to it, etc.
I also have a JTable to display the currentOrder.
The JTable is updated like this:
Code:
public void updateOrderTable() {
orderTable.setModel(new OrderTable(currentOrder).getTableModel());
}
Note that OrderTable is also a custom class to create a JTable for a given Order, and getTableModel() returns the table model.
Now, there are many different parts of the GUI that can change an order,
and every change needs to be reflected in the OrderTable.
But I want to avoid using updateOrderTable() after each button or control.
So, how do I listen to a change in the instance variable 'currentOrder' so
that every time it changes a call is made to updateOrderTable()... ?
Any advice or help?
Thanks