Thursday, October 21, 2010

CHESSBOARD INTERFACE


Introduction
This is a description of a progam that displays a chess board and its pieces in 2 dimension.
Interface
To display the interface, the source code imported some classes from the SWING package and the AWT package, of the java API (Application Programming Interface). The two packages provided the required classes and methods for the achievement of the program’s intended purpose.

Ø  Chessboard 
Figure 1: Chessboard

The graphics context object above was created from a class called Graphics2D. The code that displayed it was placed in the paint method. The paint method received the graphics context for the component as a parameter. The paint method of this code was called by Swing whenever a component needs to be repainted for any reason.
After creating the chessboard, pieces were placed on it as shown in figure 2.

Ø  Chessboard and pieces
Figure 2: chessboard and pieces

A folder containing image icons of the chesspieces was stored in a disk c. Thus, image icon constructor was used to insert the pieces on the chessboard by using the location of the image icon folder as a parameter in the image icon constructor. 

No comments:

Post a Comment