drawing tower of hanoi

Joseph Mack NA3T <[email protected]> Sat, 18 Jun 2011 06:30:12 -0700 (PDT)
Newsgroups gmane.org.user-groups.trijug.juglist
Message-ID <[email protected]>
I'm new to java. I have code which runs the tower of hanoi 
(ToH) from start to finish for any number of disks. I've 
implemented it with

o a Tower object, which has 3 poles, each of which is an 
int[] holding the size of the disk at each position on the 
pole. A methode move_disks() handles the sequence of moving 
the disks.

o a class DrawRectangles extends JPanel which calls 
paintComponent(Graphics g). To simulate a ToH, I hand code a 
set of 3 int[] in the paintComponents method, and have 
DrawRectangles draw an arbitary static ToH

I now want the state of the Tower to be (re)displayed each 
time a disk is moved and I have little idea how to do this.

o I assume the DrawRectangles class needs to be repainted

o I assume after every move in move_disks() that the repaint 
method needs to be called with the new state of the Tower.

Assuming this is the way to do it, the only code I can find 
that does similar things, is repainting screens following 
mouse clicks where a depressed button needs to be shown. 
Code that detects an event needs to written (eg a mouse 
listener).

It's not clear to me how to let the DrawRectangles class 
know about the new state of the Tower and to repaint itself.
Is the mouse clicks events the model I should use?

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!