|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent org.jogre.client.awt.JogreComponent org.jogre.client.awt.AbstractBoardComponent
This graphical component can be extended to create a number of graphical boards such as chess boards, etc. Various attributes can be set such as the number of cells, the cell size and cell spacing (in pixels). Also the width of the border can be specified, and the option of drawing letters/text on the border. Also all the colours can be set of the board.
To use
and override the
paintComponent (Graphics g)
method as follows:
paintComponent (Graphics g) { // call paintComponent in AbstractBoardComponent which will draw an empty board super (g); // Insert specifiec custom graphic drawing here }
Nested Class Summary |
Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
protected int |
borderWidth
Width of the border in pixels. |
protected Color |
cellColour1
Colour of cell one. |
protected Color |
cellColour2
Colour of cell two. |
protected int |
cellSize
Size of cell in pixels. |
protected int |
cellSpacing
Spacing between cells in pixels. |
static int |
DEFAULT_BORDER_WIDTH
Default border width (15 pixels). |
static int |
DEFAULT_CELL_SIZE
Default cell size (36 pixels). |
static int |
DEFAULT_CELL_SPACING
Default cell spacing (1 pixel). |
static int |
DEFAULT_MOUSE_BORDER_WIDTH
Default mouse border width (2 pixels). |
protected Point |
dragPoint
Stores the value of where the point is being dragged. |
protected boolean |
isAlternateBackground
Boolean to indicate alternate style background. |
protected boolean |
isDrawLetters
If true letters/numbers are drawn on the left and bottom of the board. |
protected boolean |
isReversed
If this variable is true the board will be flipped. |
protected Color |
mouseBorderColour
Colour of the mouse border. |
protected int |
mouseBorderWidth
Width of the mouse border. |
protected int |
numOfCols
Number of columns in the board. |
protected int |
numOfRows
Number of rows in the board. |
static Point |
OFF_SCREEN_POINT
Constant to show a cell point is off the board (not selected). |
protected Point |
pressedPoint
Stores the value of a mouse down. |
protected Color |
spacingColour
Colour of spacing colour. |
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 java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
AbstractBoardComponent(int numOfRows,
int numOfCols)
Default constructor which sets the number of rows and the number of columns and everything else uses it default value. |
|
AbstractBoardComponent(int numOfRows,
int numOfCols,
int cellSize,
int cellSpacing,
int borderWidth,
int mouseBorderWidth,
boolean isReversed,
boolean alternateBackground,
boolean drawLetters)
This constructor sets all the various things of a board such as its number of rows/columns, cell size, spacing between cells, border width, mouse border width and the option to draw letters down the side. |
Method Summary | |
protected void |
drawBoardBackground(Graphics g)
Draws the board background (all the various cells). |
protected void |
drawBorder(Graphics g)
This method wipes the board and draws the border. |
Point |
getBoardCoords(int screenX,
int screenY)
This methods returns a board co-ordinate (in the top-left) from a screen point. |
int |
getBorderWidth()
Return the width of the border in pixels. |
int |
getCellSize()
Return the size of each cell in pixels. |
int |
getCellSpacing()
Return the spacing between each cell in pixels. |
Point |
getDragPoint()
Sets the drag point of a mouse. |
Point |
getPressedPoint()
Return the point where a user has pressed on the board. |
Point |
getScreenCoords(int boardX,
int boardY)
This methods returns a screen co-ordinate (in the top-left) from a board point. |
boolean |
isReversed()
Returns true if a board is reversed. |
void |
paintComponent(Graphics g)
Draws the board. |
void |
resetPoints()
Reset the dragPoint and pressedPoint variables. |
void |
setColours(Color cellColour1,
Color cellColour2,
Color spacingColour,
Color mouseBorderColour)
Set up colours for this board. |
void |
setDragPoint(Point dragPoint)
Sets the drag point. |
void |
setPressedPoint(Point pressedPoint)
Sets pressed point in the board. |
void |
setReversed(boolean isReversed)
Sets if a board is reversed or not. |
Methods inherited from class org.jogre.client.awt.JogreComponent |
setController, update |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Observer |
update |
Field Detail |
public static final Point OFF_SCREEN_POINT
public static final int DEFAULT_CELL_SIZE
public static final int DEFAULT_CELL_SPACING
public static final int DEFAULT_BORDER_WIDTH
public static final int DEFAULT_MOUSE_BORDER_WIDTH
protected int numOfRows
protected int numOfCols
protected int cellSize
protected int cellSpacing
protected int borderWidth
protected int mouseBorderWidth
protected boolean isDrawLetters
protected boolean isAlternateBackground
protected boolean isReversed
protected Color cellColour1
protected Color cellColour2
protected Color spacingColour
protected Color mouseBorderColour
protected Point pressedPoint
protected Point dragPoint
Constructor Detail |
public AbstractBoardComponent(int numOfRows, int numOfCols)
numOfRows
- Number of rows in the board.numOfCols
- Number of columns in the board.public AbstractBoardComponent(int numOfRows, int numOfCols, int cellSize, int cellSpacing, int borderWidth, int mouseBorderWidth, boolean isReversed, boolean alternateBackground, boolean drawLetters)
numOfRows
- Number of rows in the board.numOfCols
- Number of columns in the board.cellSize
- Size of each cell in pixels.cellSpacing
- Spacing between each cell in pixels.borderWidth
- Size of the border in pixels.mouseBorderWidth
- Size of the mouse border in pixels.isReversed
- Boolean to indicate if the board is displayed
in reverse.alternateBackground
- Alternate style background e.g. chess style.drawLetters
- If true draw letters horizontally and numbers
vertically.Method Detail |
public void paintComponent(Graphics g)
JComponent.paintComponent(java.awt.Graphics)
public final void setColours(Color cellColour1, Color cellColour2, Color spacingColour, Color mouseBorderColour)
cellColour1
- Colour for the first cell colour.cellColour2
- Colour for the second cell colour.spacingColour
- Colour of the spacing between the cells.mouseBorderColour
- Colour of the mouse border colour.protected void drawBoardBackground(Graphics g)
g
- Graphics object.protected void drawBorder(Graphics g)
g
- public Point getScreenCoords(int boardX, int boardY)
boardX
- 0 < boardX < numOfColumnsboardY
- 0 < boardY < numOfRows
public Point getBoardCoords(int screenX, int screenY)
screenX
- X co-ordinate in pixels.screenY
- Y co-ordinate in pixels.
public boolean isReversed()
public int getBorderWidth()
public int getCellSize()
public int getCellSpacing()
public Point getPressedPoint()
public Point getDragPoint()
public void setReversed(boolean isReversed)
isReversed
- True if reversed (e.g. black side in chess).public void setPressedPoint(Point pressedPoint)
pressedPoint
- Point on board where pressed.public void setDragPoint(Point dragPoint)
dragPoint
- Point on board where dragged.public void resetPoints()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |