Class boardview

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--boardview
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class boardview
extends java.awt.Canvas
implements java.lang.Runnable

a boardview is a canvas (a rectangle that can be displayed on the screen and painted on) that can display a board. It can be used in two ways

  1. by an applet. In this case the boardview listens to the mouse, and lets the players do moves. It also starts an animation for fading in any changes.
  2. By genetictrain. Animation is no longer needed, and it does not listen to the mouse.

See Also:
Serialized Form

Inner classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
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
boardview(board ib)
          constructor in non-applet mode
boardview(board ib, reversi ir)
          constructor for applet mode
 
Method Summary
 void answer(java.lang.String s, int m)
          this method is called by movers to return return the move they want to do.
 void display()
          creates a frame that shows this boardview.
 void domove(int m)
          do the given move on the board.
 boolean mouseDown(java.awt.Event evt, int x, int y)
          this method is called if the user clicked the mouse.
 void paint(java.awt.Graphics newg)
          this method is called by the operating system if the frame must be redrawn, and by the rest of the program if something changed on the board.
 void run()
          this method is the one that runs in its own thread to do the animation. it calls fade() every 150 milliseconds.
 void setplayers(boolean a, boolean b)
          you can indicate here whether computer players must be used.
 void start()
          is called if a new thread is created for the animation.
 void stop()
          is called if someone wants the thread to stop.
 void undomove()
          undo the last move on the board.
 
Methods inherited from class java.awt.Canvas
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

boardview

public boardview(board ib,
                 reversi ir)
constructor for applet mode

boardview

public boardview(board ib)
constructor in non-applet mode
Method Detail

display

public void display()
creates a frame that shows this boardview. Used in nonapplet-mode.

mouseDown

public boolean mouseDown(java.awt.Event evt,
                         int x,
                         int y)
this method is called if the user clicked the mouse.
Overrides:
mouseDown in class java.awt.Component
Parameters:
evt - an object that contains details on the click.
x - the horizontal position of the cursor
y - the vertical position
Returns:
true to indicate success

domove

public void domove(int m)
do the given move on the board.
Parameters:
m - the move to be done.

undomove

public void undomove()
undo the last move on the board.

setplayers

public void setplayers(boolean a,
                       boolean b)
you can indicate here whether computer players must be used.
Parameters:
a - true if a computer player must be used for the first player. False if the user operates this player.
b - same for second player.

paint

public void paint(java.awt.Graphics newg)
this method is called by the operating system if the frame must be redrawn, and by the rest of the program if something changed on the board. It is synchronized because genetictrain calls this method very often, and we do not want these paints to happen in parallel.
Overrides:
paint in class java.awt.Canvas

answer

public void answer(java.lang.String s,
                   int m)
this method is called by movers to return return the move they want to do.
Parameters:
s - s is not used. It is a little joke: it can be used by callers to give a comment to this function.
m - the move to be done.

start

public void start()
is called if a new thread is created for the animation.

stop

public void stop()
is called if someone wants the thread to stop.

run

public void run()
this method is the one that runs in its own thread to do the animation. it calls fade() every 150 milliseconds.
Specified by:
run in interface java.lang.Runnable