[Implementation] Pentris – Board

Basic structure for Board class was finished: general GUI is done.

Check the source code posted. The class uses bunch of buttons to simulate what I want.

package gygd.pentris.choi;
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

 * board class
 * @author Wonjohn Choi
public class Board extends JPanel {
	//array to control each block
	protected JButton[][] blockGrid;

	//mathematical grid
	protected boolean[][] grid;

	static final boolean EMPTY = false;
	static final boolean FILLED = true;

	//width and height of the board
	protected int HEIGHT, WIDTH;

	public Board(int height, int width){
		HEIGHT = height; WIDTH = width;

		grid = new boolean[HEIGHT][WIDTH];
		blockGrid = new JButton[HEIGHT][WIDTH]; //instantiate
		setLayout(new GridLayout(HEIGHT, WIDTH)); //set its layout

		//for each and every block,
		for(int row=0;row<HEIGHT;row++){
			for(int col=0;col
				blockGrid[row][col] = new JButton();//set each block as a button
				blockGrid[row][col].setBorder(new LineBorder(Color.getHSBColor(0, 0,0.8F)));//set its border color
				blockGrid[row][col].setEnabled(false);//disable it
				add(blockGrid[row][col]);//add to the panel

		setSize(WIDTH*30, HEIGHT*30); //set the size (each block has a size length of 30)

	public static void main(String args[]){
		JFrame test = new JFrame();
		Board board = new Board(20, 20);
		test.setSize(board.WIDTH*30, board.HEIGHT*30);




The left image is earned by running above code.


About Wonjohn Choi
Hello, I am a software developer Wonjohn Choi. I live in Mississauga, Ontario, Canada and study at a school called St. Francis Xavier Secondary School. My core interests include Math, Computer Science, and Engineering. Thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: