Assignment 4
CSC 115 -- Fall 2002
Objectives
- Practice using object-oriented user interfaces
- Introduction to listeners and multiple views
- Practice with code reuse
- Extended practice with the Iterator interface
- Trees and manipulating trees
- Experience with Swing JTree objects
-
Practice doing pair programming
Instructions
Part I of the assignment is to be done with a fellow classmate.
Pair up with a partner during the lab or use the webboard. Part II
should be done alone.
Part I
The goal of this part of the assignment is to gain experience using many
of the Java 2 built in classes and interfaces. During the past
week or two in class, we have learned how to write our own Tree class
and tree iterators. In this assignment you will learn how to use
some of the built-in classes in Java for creating and manipulating
trees.
As a first step, you should familiarize yourself with JTrees from the
Java sun tutorial:
JTtrees:
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
You should explore and thoroughly understand the following examples
from this tutorial (these examples will be described in detail in the
lab, so do not miss your lab this week!):
You will also need to know how to use the following provided classes:
You and your partner should explore these built in classes
and interfaces together, taking turns to explain the code to each other.
You should understand all of this code thoroughly before attempting any
implementation. While you explore, take turns editing the example
code to explore it more deeply. (Note: you will need to
describe how you worked with your partner for Part II of the
assignment.)
Implementation requirements
For this assignment, you will learn how to use a graphical
representation of a tree using the tree built in classes and interfaces
in Java. Using the DynamicTree and DynamicTreeDemo
example classes mentioned above as a starting point, your graphical tree
view will have controls which will allow a user to add and remove
nodes from the tree, as well as a button to empty the tree. The
user can also expand and collapse branches in the tree.
You need to add a text area to the bottom of the tree window
that will display preorder, inorder and postorder traversals of
the visible parts of the tree. Therefore, when the user
changes the tree by adding a node, removing a node, renaming a
node or clearing the tree, the traversals should be updated. The
DynamicTree example already has listeners for when a user adds, removes
or clears the tree. You need to add code to these listeners
to create your traversal display. You will also need to add
a listener for when the user collapses or expands a branch in the tree.
You are free to design the output style of the tree traversals (bonus
marks will be awarded for outstanding displays of the traversals).
The only requirement is that your output is clear and that it is
intuitive for the user to read the traversals and that they map
correctly to the visible tree.
Hints
- Make sure you understand the interactive examples we
covered in class
- Implement this program incrementally.
- It is imperative you attend the labs this week and
that you understand the code listed above before trying to do this
assignment. You should also attend the labs during the week of
Nov 18th and Nov 25th for more help should you need it.
- The DynamicTreeDemo example above does
most of what you need for this assignment -- start with this and add
a text area for displaying output (the listeners will
- Hints: for improving the text output of your
tree traversals, see this link
http://java.sun.com/docs/books/tutorial/uiswing/components/label.html
in the Java tutorial.
- For tips on how to add the
expansion listener, see
http://java.sun.com/docs/books/tutorial/uiswing/events/treeexpansionlistener.html
- Develop this assignment in this order:
- First create a text area and write one of the traversals to this
area. At first just print out the entire tree even the nodes
that are not visible. Just get one traversal type working, and
then add the others later.
- Next add the listeners for tree contraction and expansion
events. Note -- these listeners should be attached to the
DynamicTree class (see the simpler TreeDemo example for a
similar example).
- Once you are sure your listeners are working correctly (just do
prints to make sure they work), then adapt your traversal text
output so that it only shows nodes that are visible (hint:
the JTree class has an isVisible() method.... see the API for JTree).
Part II
For Part II, you are to write a description of your experiences doing
pair programming and design (one to two pages). You
should write this summary alone. In your essay, you should discuss
which aspects of pair programming you found useful, how it helped you
learn (or how you helped your partner learn) and what you would do
differently the next time you had to do pair programming.
Your short essay should be typed and spell checked.
Due dates
- The code for Part I should be submitted electronically on
Thursday, 28th November by 3pm (you will need to hand in your edited
versions of DynamicTree.java and DynamicTreeDemo.java).
- Part II
should be handed in before class on Thursday, 28th November.
Also hand in a printout of your code from Part I on Thursday.
-
Clearly print both student names and student numbers on the code
that you hand in.
Remarks
The graders are instructed to take the following points into account when marking your assignment:
- Part 1:
- Correctness of your program.
- Simplicity of your code.
- Presentation style of your tree traversals.
- Meaningful variable and method names.
- Use of comments
- Part 2:
- Clarity of writing
- Quality and depth of your observations (if you don't do the
exercise doing pair programming, this part will be hard to write!)