Tutorial 6: AWT GUI Programming, MVC
Introduction
This tutorial covers:
- Building a Soda Machine GUI application using AWT.
- Model-View-Controller Paradigm.
I. The Model: SodaMachine.class
Exercises:
- Copy the byte code of the class SodaMachine, ~comp212/tutorials/06/SodaMachine.class to your local directory:
- Look at the javadoc documentation for SodaMachine. Run SodaMachine to get an idea how the model behaves.
- Do the following only after you have built the GUI in part II: if time permits,
write Java code to implement SodaMachine. Use StructureBuilder to reverse engineer
if necessary.
II. The View: SodaGUI.class
Exercises:
- Copy the byte code of the class SodaGUI, ~comp212/tutorials/06/SodaGUI*.class to your local directory. Note: Do NOT compile SodaGUI.java. It is stub code so that the SodaControl will compile.
- Look at the javadoc documentation for SodaGUI. Run SodaGUI to get an idea how the view looks like.
- The given GUI is an incomplete GUI. Write Java code to implement SodaGUI as given. Use StructureBuilder to reverse engineer if necessary. Add hooks to install listeners for the appropriate components, which include but are not limited to:
- void addTakeMoneyToken( ActionListener al )
- void addCokenListener( ActionListener al)
- void addCokenListener( ActionListener al)
- void updateView(SodaMachine soda)
- String getInput()
- void setOutput(String s)
See today's handouts FLGUI Doc and FLGUI.java
- Add more components to the GUI to make it more "complete". NOTE: Dr. Java does not work with the java AWT so you need to use SB or emacs or whatever editor you use.
III. The Controller: SodaControl.java
Exercises:
- Review today's handouts FLGUI Doc and FLControl.java.
- Write the controller class SodaControl.java to glue the above model and view together.
D. X. Nguyen, Sept. 26, 1999.
dxnguyen@cs.rice.edu