TowerPanel -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //******************************************************************** // TowerPanel.java Author: Lewis/Loftus // // Solution to Programming Project 11.11 // // Controls the graphical display of the Towers of Hanoi //******************************************************************** import javax.swing.*; import javax.swing.Timer; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; public class TowerPanel extends JPanel { TowersOfHanoi towerEngine; Tower towers; int numDisks; int pauseTime; int firstTower; // boolean solved; boolean userSolve; boolean firstTowerSelected; ArrayList solution; Timer animationTimer; static final int MIN_PAUSE_TIME = 50; static final int MAX_PAUSE_TIME = 1500; static final int DEFAULT_PAUSE_TIME = 900; static final int MIN_DISKS = 1; static final int MAX_DISKS = 8; static final int DEFAULT_NUM_DISKS = 4; static final int NUM_TOWERS = 3; final String TRY_AGAIN_MESSAGE = "Incorrect move\n Try Again?"; final String SOLVED_MESSAGE = "Congratulations!\nYou solved the puzzle!"; //----------------------------------------------------------------- // Creates a new tower panel to diplay the Towers of Hanoi //----------------------------------------------------------------- public TowerPanel(int disks) { numDisks = disks; pauseTime = DEFAULT_PAUSE_TIME; solution = new ArrayList(); userSolve = false; firstTowerSelected = false; towers = new Tower[NUM_TOWERS]; for (int i=0; i<NUM_TOWERS; i++) towers[i] = new Tower(numDisks); //add sized disks to first tower for (int i=numDisks; i>0; i--) towers[0].addDisk(new Disk(i)); towerEngine = new TowersOfHanoi(numDisks); setBackground(Color.white); addMouseListener(new TowerSelectListener()); } //----------------------------------------------------------------- // Overrides JPanels getPreferredSize()....
View Full Document

Page1 / 6

TowerPanel -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online