YCP Logo Lecture 21: Designing and Implementing a GUI (Part IV)

Make PizzaView implement the Observer interface.

Add setModel and setView methods to PizzaView.

Implement the update method in PizzaView so that when the model object changes, the view is updated appropriately.

Add event handlers for the "Add >>" and "<< Remove" buttons to add and remove toppings. The handlers delegate to the controller object, which in turn modifies the underlying model (Pizza) object.

Add event handler for the size combo box, again delegating size changes through the controller.

Finally, change the main method in the Main class to create the model, controller, and view objects, hook them up, and create a JFrame in which the view is displayed.

Issue: the view does not initially display any data, because no update to the model object has occurred. Use SwingUtilities.invokeLater to insert a callback object that will explicitly call the PizzaView object's update method.

The final code:


This is a project developed with the Netbeans Java IDE.