CSE 283 Introduction to Object Oriented Design

Barbara Nostrand, Ph.D.

CSE 283 Labs
Welcome to the site for CSE 283 Labs!


Lab 13: Animation

Prev | Next | Lab 13



In today's exercise,  we will convert a text based program into one that uses a GUI.  The application we will change solves the Towers of Hanoi Problem.  The “Towers of Hanoi” puzzle was invented by Edouard Lucas,  a French mathematician, around 1883.  The puzzle can be stated as follows:  There are 3 needles and a tower of disks on the first one,  with the smaller on the top and the bigger on the bottom.  The purpose of the puzzle is to move the whole tower from the first needle to the second,  by moving only one disk every time and by observing not to put a bigger disk atop of a smaller one.  The legend that is popularly attached to it appeared in,  among others,  the “Metamagical Themas” column of the Scientific American magazine:

In the great temple of Brahma in Benares,  on a brass plate under the dome that marks the center of the world,  there are 64 disks of pure gold that the priests carry one at a time between these diamond needles according to Brahma’s immutable law:  No disk may be placed on a smaller disk.  In the begging of the world all 64 disks formed the Tower of Brahma on one needle.  Now,  however,  the process of transfer of the tower from one needle to another is in mid course.  When the last disk is finally in place,  once again forming the Tower of Brahma but on a different needle,  then will come the end of the world and all will turn to dust. 

A recursive solution to the Tower of Hanoi problem can be found in Chapter 8.  The GUI version of this program will employ a GUI form to obtain the source spike,  the destination spike,  and the number of disks in the tower.  The solution will be graphically displayed to the user who will use buttons to tell the program to either speed up moving the disks,  slow down moving the disks,  move a single disk,  start a new tower,  or exit the program. 

Classes and Objects

By this time,  class specifications should be fairly familiar to you.  Thus,  part of your task for this project is to write class specifications similar to what you have seen in previous exercises.  Obviously,  you will need a Disk class to represent each disk and a Tower class to represent each tower.  Each disk will be responsible for drawing its own image.  Each tower,  will be responsible for drawing the collection of disks courrently on it.  In our description above,  there is also a brass plate.  This should also be an object and should be drawn.  You probably also want to draw needle objects as well.  Finally,  you will need some sort of control panel object which has a collection of buttons and you will need to use some sort of GUI object to request tower specifications from the user. 

Test and Debug

Test your code thoroughly and fix any bugs that you find.  As this program will be an applet,  you will be able to install it on your personal web page if you wish.  You can test your applet in JGRASP by clicking on the run applet button. 


Phrases you should now understand:

Event, Event Queue, Listener, Button, Transition Diagram, State, addActionListener(),actionPerformed(), repaint().


Prev | Next | Lab 13




Lab 0

Lab 1

Lab 2

Lab 3

Lab 4

Lab 5

Lab 6

Lab 7-8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13

Last modified: 2007 OCT 24