Comp 212 Lab 10: Tournament Tree MVC
Introduction
This tutorial will lead you through the process of putting together an MVC
design for the Tournament tree in milestone 1 for programming
project #3. Most of the effort should be spent on implementing the
algorithm for inserting a known team into the Tournament tree. In the end, you should come up with an appropriate MVC design
for the Tournament tree GUI application and a (perhaps partial) implementation of each of
the components of the MVC design. You are allowed to work in teams
of two or three during the lab session and share the code with your lab
partners. After the lab session, you are to take your lab code and work
alone to complete milestone 1 for programming
project #3.
Tournament View
From the demo
applet, we see that the view frame has the following required GUI
components.
- What it looks like.
- A "Clear" button to clear all the tournament tree displays.
- A JTextField to enter the name of a known team.
- A "Insert" button to insert the known team with the name
shown in the text box into the tournament tree.
- A "Make Tournament" button to randomly create a tournament
tree.
- A "Play Round" button to play one round of the current
tournament.
- A JTextArea to display the tournament tree vertically in text
format. This JTextArea should be scrollable.
- A JPanel to graphically display the current tournament tree
horizontally. This JPanel should be scrollable.
- A JLabel to display the winner of the tournament.
- What it behaves like.
- We are going to limit our lab work to the Clear button, the JTextField
for team names, the Insert button, and the scrollable JTextArea for
displaying the current tree. By now, you ought to know all about Java GUI components and their event
listeners.
- What should the action listener for the Clear button do?
- What should the action listener for the Insert button do?
- How do we make a scrollable JTextArea? The Notes
and Hints section of the programming project explains how to do it.
- How it is created and initialized.
- It is the controller that creates the view and pass to it appropriate
concrete adapters at construction time. The controller design is discussed in a
latter section.
Tournament Model
Again, we are going to focus only a model that allows us to insert teams into
a tournament tree.
- What it looks like- The tournament model comprises of
- a BiTree representing a tournament tree and containing unknown and
known teams - what design pattern(s) are we going to use here?
- What it behaves like
- How it is created and initialized.
- It is the controller that creates the model. When the model
comes into existence, what does it initialize its tournament tree to?
Tournament Tree Controller
The Tournament controller instantiates the model and the view, and set up the
"wiring" between the two using appropriate adapter.
- What it looks like - The controller maintains
- a Tournament model object
- a Tournament view object
- What it behaves like.
- How is it created and initialized.
- when it comes into existence, it instantiates a Tournament model and
a Tournament view passing to this view the appropriate adapters.
A viable alternative is to have the controller construct the system when a
method is called, rather than in its constructor.
D. X. Nguyen, Nov. 04, 2001
dxnguyen@cs.rice.edu