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.AccessibleJFrame
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.Type
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
If set to true, will automatically delay by valuedtime
at end of calls todrawdot(int,int)
protected int
the height in pixels of graphical square representing a maze coordinateprotected int
the width in pixels of graphical square representing a maze coordinateprotected Color
The color of the graphical circle drawn by default bydrawdot(int,int)
protected int
The approximate number of milliseconds delayed in calls todrawdot(int,int)
ifautodelay
is set to trueprotected String
The path-name of the gif/jpeg file that replaces a circle ifusegif
is set to trueprotected int[][]
The array for the maze is declared and initialized in the superclass. This variable should be not set incustomize()
protected int
The number of rows of the maze 2D array.protected int
The number of columns of the maze 2D array.protected Color
The color of maze "paths", or M[row][column] values that are non-zeroprotected Color
The color of text messages that are displayed on the maze bydrawMessage(java.lang.String)
protected boolean
If set to true, thedrawblock(int,int)
function will display the values of the maze matrix that are non-zeroprotected int
Starting x coordinate of mazeprotected int
Starting y coordinate of maze: the mazebase superclass will calldigout(startdigy,startdigx)
protected boolean
If set to true, will try to load animated gif from filenamegifname
, which will be displayed bydrawdot(int,int)
protected Color
The 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, rootPaneCheckingEnabled
Fields 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_CURSOR
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
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
clear()
void
User-defined initialization code.void
delay
(int ms) delays current thread by approximately ms milliseconds.void
digout
(int y, int x) This function must be override in a subclass to generate a random maze.void
drawblock
(int y, int x) draws a graphical square of color pathcolor corresponding to matrix coordinates row y, column x.void
drawdot
(int y, int x) protected void
drawdot2
(int y, int x) void
drawgif
(int y, int x) draw default gifprotected void
draw a specific Image (such as animated gif)void
displays string message m at top row of mazeprotected Graphics
Graphics()
returns java.awt.Graphics object that allows drawing to animation buffer: nothing will be displayed, however, untilnextframe()
is called.void
Override this function to respond to keyboard events.void
void
protected void
utility to load animated gif, called from setup after customize()void
redraws animation buffer without delayvoid
nextframe
(int msdelay) redraws animation buffer after specified delayvoid
this function overrides automatic repaint: do not changevoid
play()
Optional function to override to set up an interactive gameprotected void
refresh()
void
solve()
Override this function in a subclass to solve the maze.void
trace()
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, update
Methods 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, setUndecorated
Methods 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, toFront
Methods 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, 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, 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, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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 valuedtime
at 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)
ifautodelay
is 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 ifusegif
is 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:
keyReleased
in interfaceKeyListener
-
keyTyped
- Specified by:
keyTyped
in interfaceKeyListener
-
keyPressed
Override this function to respond to keyboard events. The default function prints the numerical value corresponding to the key pressed- Specified by:
keyPressed
in interfaceKeyListener
-