Class GamePanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by GamePanel
All Implemented Interfaces:
Constants, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class GamePanel
extends javax.swing.JPanel
implements Constants, java.awt.event.MouseListener

GamePanel is a class whose objects are game squares on the game window. This class defines background colours and images on game squares. It also handles operations caused by mouse actions on game squares.

Version:
1.0.0
Author:
Michiru Nishikawa
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  java.awt.Color c
          Background colour of this game panel.
private  int numDisplayed
          Number displayed on this game panel.
private  PlusNumber owner
          PlusNumber object that creates and has this game panel.
private  int panelNumber
          Unique number of this game panel.
private  int state
          indicate if a game panel is either not selected, already selected, or alrady played.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface Constants
BIG_FONT, CREAM1, CREAM2, CYAN, IMG_FILE_NAMES_MAIN, IMG_FILE_NAMES_NUMBER, IMG_FILE_NAMES_SPLASH, INST_HEADINGS, INST_IMG_FILE_NAMES, MAX_TIME, MEDIUM_FONT, MENU_ITEM_NAMES, MENU_NAMES, NOT_SELECTED, ORANGE, PLAYED, RED, SELECTED, SMALL_FONT, SMALLER_FONT, SMALLEST_FONT, SOUND_FILE_NAMES, YELLOW
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GamePanel()
          Default constructor that initialises attributes by caling a non-default constructor.
GamePanel(PlusNumber owner, java.awt.Color c, int panelNumber)
          Constructor that initialises all attributes, adds a mouse listener of myself, and sets a size of this panel.
 
Method Summary
 int getState()
          Return the value of the "state" attribute.
 void mouseClicked(java.awt.event.MouseEvent e)
          Add the number displayed on the clicked square to the total sum.
 void mouseEntered(java.awt.event.MouseEvent e)
          Empty method overring a method of the MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent e)
          Empty method overring a method of the MouseListener interface.
 void mousePressed(java.awt.event.MouseEvent e)
          Empty method overring a method of the MouseListener interface.
 void mouseReleased(java.awt.event.MouseEvent e)
          Empty method overring a method of the MouseListener interface.
 void paint(java.awt.Graphics g)
          Fill a background colour of a game panel and paint an image of a number on it.
private  void processAfterOneSecond(java.lang.String sessionState)
          Configure a schedule of a Timer object and start it.
private  void processCorrect()
          Called when a number is clicked and the total sum becomes equals to a question number.
private  void processExceed()
          Called when a number is clicked and the total sum exceeds a question number.
 void setColour(java.awt.Color c)
          Update the value of the "c" attribute.
 void setNumDisplayed(int num)
          Update the value of the "numDisplayed" attribute.
 void setState(int state)
          Update the value of the "state" attribute.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

owner

private PlusNumber owner
PlusNumber object that creates and has this game panel.


c

private java.awt.Color c
Background colour of this game panel.


panelNumber

private int panelNumber
Unique number of this game panel.


numDisplayed

private int numDisplayed
Number displayed on this game panel.


state

private int state
indicate if a game panel is either not selected, already selected, or alrady played.

Constructor Detail

GamePanel

public GamePanel(PlusNumber owner,
                 java.awt.Color c,
                 int panelNumber)
Constructor that initialises all attributes, adds a mouse listener of myself, and sets a size of this panel.

Parameters:
owner - a parent PlusNumber object.
c - a Color object which is the background colour of each panel.
panelNumber - integer representing a panel number.

GamePanel

public GamePanel()
Default constructor that initialises attributes by caling a non-default constructor.

Method Detail

setColour

public void setColour(java.awt.Color c)
Update the value of the "c" attribute.

Parameters:
c - a new Color object representing a background colour of a game panel.

setState

public void setState(int state)
Update the value of the "state" attribute.

Parameters:
state - integer that indicates if that panel has not been selected (0), already selected (1), or already played (2).

setNumDisplayed

public void setNumDisplayed(int num)
Update the value of the "numDisplayed" attribute.

Parameters:
num - integer that is a new number displayed on the game square.

getState

public int getState()
Return the value of the "state" attribute.

Returns:
Integer that indicates the state of a game panel; either 0 (selected), 1 (already selected), or 2 (already played)

paint

public void paint(java.awt.Graphics g)
Fill a background colour of a game panel and paint an image of a number on it.

Overrides:
paint in class javax.swing.JComponent
Parameters:
g - a type Graphic object.

processCorrect

private void processCorrect()
Called when a number is clicked and the total sum becomes equals to a question number. Display a message and call the next method after one second of delay.


processExceed

private void processExceed()
Called when a number is clicked and the total sum exceeds a question number. Display a message and call the next method after one second of delay.


processAfterOneSecond

private void processAfterOneSecond(java.lang.String sessionState)
Configure a schedule of a Timer object and start it. The timer will call the next method after 1 second.

Parameters:
sessionState - string representing a current session state.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Add the number displayed on the clicked square to the total sum. Then switch the next opearation by comparing the sum and the question number.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - a mouse event happened on a game square, which is clicking.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Empty method overring a method of the MouseListener interface.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - a MouseEvent when a mouse enters over a panel.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Empty method overring a method of the MouseListener interface.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - a MouseEvent when a mouse exits from a panel.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Empty method overring a method of the MouseListener interface.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - a MouseEvent when a mouse is pressed on a panel.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Empty method overring a method of the MouseListener interface.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - a MouseEvent when a mouse pressing finishes on a panel.