Class mazebase
- All Implemented Interfaces:
KeyListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible,RootPaneContainer,WindowConstants
Superclass of maze generation/solution assignments for CSC17.
Protected fields, except the 2D arrayM, can be modified by
overriding the customize() function in a subclass.
This class does not contain a main, which should be supplied in a subclass.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrameNested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrameNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIf set to true, will automatically delay by valuedtimeat end of calls todrawdot(int,int)protected intthe height in pixels of graphical square representing a maze coordinateprotected intthe width in pixels of graphical square representing a maze coordinateprotected ColorThe color of the graphical circle drawn by default bydrawdot(int,int)protected intThe approximate number of milliseconds delayed in calls todrawdot(int,int)ifautodelayis set to trueprotected StringThe path-name of the gif/jpeg file that replaces a circle ifusegifis set to trueprotected int[][]The array for the maze is declared and initialized in the superclass. This variable should be not set incustomize()protected intThe number of rows of the maze 2D array.protected intThe number of columns of the maze 2D array.protected ColorThe color of maze "paths", or M[row][column] values that are non-zeroprotected ColorThe color of text messages that are displayed on the maze bydrawMessage(java.lang.String)protected booleanIf set to true, thedrawblock(int,int)function will display the values of the maze matrix that are non-zeroprotected intStarting x coordinate of mazeprotected intStarting y coordinate of maze: the mazebase superclass will calldigout(startdigy,startdigx)protected booleanIf set to true, will try to load animated gif from filenamegifname, which will be displayed bydrawdot(int,int)protected ColorThe color of maze "walls", or M[row][column] values that are zeroprotected int"y-offset", which is required on some systems that automatically displays a title bar for every window.Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSORFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclear()voidUser-defined initialization code.voiddelay(int ms) delays current thread by approximately ms milliseconds.voiddigout(int y, int x) This function must be override in a subclass to generate a random maze.voiddrawblock(int y, int x) draws a graphical square of color pathcolor corresponding to matrix coordinates row y, column x.voiddrawdot(int y, int x) protected voiddrawdot2(int y, int x) voiddrawgif(int y, int x) draw default gifprotected voiddraw a specific Image (such as animated gif)voiddisplays string message m at top row of mazeprotected GraphicsGraphics()returns java.awt.Graphics object that allows drawing to animation buffer: nothing will be displayed, however, untilnextframe()is called.voidOverride this function to respond to keyboard events.voidvoidprotected voidutility to load animated gif, called from setup after customize()voidredraws animation buffer without delayvoidnextframe(int msdelay) redraws animation buffer after specified delayvoidthis function overrides automatic repaint: do not changevoidplay()Optional function to override to set up an interactive gameprotected voidrefresh()voidsolve()Override this function in a subclass to solve the maze.voidtrace()Override this function to trace the optimal solution path of the maze.Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateMethods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecoratedMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTreeMethods 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, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Field Details
-
mheight
protected int mheightThe number of rows of the maze 2D array. This number should be odd in order for the maze to have a border. The default value is 41. -
mwidth
protected int mwidthThe number of columns of the maze 2D array. This number should be odd in order for the maze to have a border. The default value is 41. -
M
protected int[][] MThe array for the maze is declared and initialized in the superclass. This variable should be not set incustomize() -
showvalue
protected boolean showvalueIf set to true, thedrawblock(int,int)function will display the values of the maze matrix that are non-zero -
autodelay
protected boolean autodelayIf set to true, will automatically delay by valuedtimeat end of calls todrawdot(int,int) -
usegif
protected boolean usegifIf set to true, will try to load animated gif from filenamegifname, which will be displayed bydrawdot(int,int) -
bh
protected int bhthe height in pixels of graphical square representing a maze coordinate -
bw
protected int bwthe width in pixels of graphical square representing a maze coordinate -
yoff
protected int yoff"y-offset", which is required on some systems that automatically displays a title bar for every window. -
dtime
protected int dtimeThe approximate number of milliseconds delayed in calls todrawdot(int,int)ifautodelayis set to true -
wallcolor
The color of maze "walls", or M[row][column] values that are zero -
pathcolor
The color of maze "paths", or M[row][column] values that are non-zero -
dotcolor
The color of the graphical circle drawn by default bydrawdot(int,int) -
pencolor
The color of text messages that are displayed on the maze bydrawMessage(java.lang.String) -
gifname
The path-name of the gif/jpeg file that replaces a circle ifusegifis set to true -
startdigx
protected int startdigxStarting x coordinate of maze -
startdigy
protected int startdigyStarting y coordinate of maze: the mazebase superclass will calldigout(startdigy,startdigx)
-
-
Constructor Details
-
mazebase
public mazebase()constructor calls customize first, then creates the matrix M
-
-
Method Details
-
Graphics
returns java.awt.Graphics object that allows drawing to animation buffer: nothing will be displayed, however, untilnextframe()is called. -
loadgif
utility to load animated gif, called from setup after customize() -
paint
this function overrides automatic repaint: do not change -
clear
protected void clear() -
refresh
protected void refresh() -
nextframe
public void nextframe()redraws animation buffer without delay -
nextframe
public void nextframe(int msdelay) redraws animation buffer after specified delay- Parameters:
msdelay- The approximate number of milliseconds to delay
-
delay
public void delay(int ms) delays current thread by approximately ms milliseconds. This function is non-blocking. -
drawblock
public void drawblock(int y, int x) draws a graphical square of color pathcolor corresponding to matrix coordinates row y, column x. -
drawdot
public void drawdot(int y, int x) -
drawdot2
protected void drawdot2(int y, int x) -
drawgif
public void drawgif(int y, int x) draw default gif -
drawgif2
draw a specific Image (such as animated gif) -
drawMessage
displays string message m at top row of maze -
customize
public void customize()User-defined initialization code. This function can be overridden in a subclass. The default, base class version does nothing. This function is called by the constructor of base class -
digout
public void digout(int y, int x) This function must be override in a subclass to generate a random maze. The default, base-class version does nothing. -
solve
public void solve()Override this function in a subclass to solve the maze. Start at coordinates x=1, y=1, and stop at coordinates x=mwidth-1, y=mheight-2. -
trace
public void trace()Override this function to trace the optimal solution path of the maze. -
play
public void play()Optional function to override to set up an interactive game -
keyReleased
- Specified by:
keyReleasedin interfaceKeyListener
-
keyTyped
- Specified by:
keyTypedin interfaceKeyListener
-
keyPressed
Override this function to respond to keyboard events. The default function prints the numerical value corresponding to the key pressed- Specified by:
keyPressedin interfaceKeyListener
-