net.pacbell.jfai.toh
Class TowerOfHanoi

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by net.pacbell.jfai.toh.util.AbstractJMainFrame
                          extended by net.pacbell.jfai.toh.TowerOfHanoi
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer

public class TowerOfHanoi
extends AbstractJMainFrame

This class is the entry point to solve and visualize the "Tower Of Hanoi" puzzle.

There is a base with three pins to accept disks. Each disk has a certain size. At the beginning all disks are stacked on one pin. The goal is to move the stack to another empty pin.

Legal moves:

  1. Any disk can go onto the base.
  2. 2. A smaller disk can go onto a larger disk.
  3. 3. Only one disk at a time can move.

Author:
Jürgen Failenschmid
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class net.pacbell.jfai.toh.util.AbstractJMainFrame
ARGUMENT_HEIGHT, ARGUMENT_WIDTH
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TowerOfHanoi()
          Create an instance for use in an applet.
TowerOfHanoi(String[] args)
          Create an instance for use in a stand-alone application.
 
Method Summary
protected  void buildContentPane(Container contentPane)
          (Application and Applet) Constructs the contents of the given content pane of a root container.
 void destroy()
          Applet destruction: clean up.
 Solver getSolver()
          Gets the solver.
 TowerOfHanoiView getView()
          Gets the view.
protected  void initialize(String[] args)
          (Application and Applet) Parses the given arguments. Attempts to detect if the Java 3D classes are missing (by checking for Tuple3f) and if so, creates a text component with an error message.
static void main(String[] args)
          Allows this class to be invoked as a Java application.
 String usageMessage()
          Answer a String describing how to invoke the application correctly.
 
Methods inherited from class net.pacbell.jfai.toh.util.AbstractJMainFrame
addListeners, buildWindow, getArgument, getArgument, getErrorComponent, hasErrorComponent, init, parseArguments, parseHeightArgument, parseWidthArgument, resize, setErrorComponent, usage, usage, windowTitle
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TowerOfHanoi

public TowerOfHanoi()
Create an instance for use in an applet.


TowerOfHanoi

public TowerOfHanoi(String[] args)
Create an instance for use in a stand-alone application.

Accept these arguments:

Sample invocation: TowerOfHanoi size=4 from=left to=right

Parameters:
args - The arguments found during invocation.
Method Detail

main

public static void main(String[] args)
Allows this class to be invoked as a Java application.

Parameters:
args - The arguments found during invocation.

destroy

public void destroy()
Applet destruction: clean up.

Overrides:
destroy in class Applet

getSolver

public Solver getSolver()
Gets the solver.

Returns:
the solver.

getView

public TowerOfHanoiView getView()
Gets the view.

Returns:
the view.

usageMessage

public String usageMessage()
Answer a String describing how to invoke the application correctly.

Specified by:
usageMessage in class AbstractJMainFrame
Returns:
a string describing how to invoke this application.

buildContentPane

protected void buildContentPane(Container contentPane)
(Application and Applet) Constructs the contents of the given content pane of a root container.

Specified by:
buildContentPane in class AbstractJMainFrame
Parameters:
contentPane - the content pane of a container
See Also:
AbstractJMainFrame.buildContentPane(java.awt.Container)

initialize

protected void initialize(String[] args)
(Application and Applet) Parses the given arguments. This method is called before anything else happens during instance creation. Attempts to detect if the Java 3D classes are missing (by checking for Tuple3f) and if so, creates a text component with an error message. The text displays instead of the regular view.

Overrides:
initialize in class AbstractJMainFrame
Parameters:
args - The invocation arguments. If args parameter is null, then the instance is an applet.
See Also:
AbstractJMainFrame.initialize(java.lang.String[]), AbstractJMainFrame.setErrorComponent(java.awt.Component)