Hi guys. I have had this problem for so long now it's making me feel so depressed. :x
I am trying to display 42 ovals (connect 4) on JPanel but it seems to display a huge white box at the top of the panel and the tips os 7 ovals and the rest of the JPanel is blue (the background colour is set to blue).
My CircleGrid class:
[code=java]
public class CircleGrid extends JPanel implements MouseListener, MouseMotionList ener
{
int ifRed;
int notIfRed;
boolean ifEmpty;
String currentColour = "White";
final int empty = 0;
final int competitorOne = 1;
final int competitorTwo = 2;
static final int row = 6;
static final int col = 7;
Circle [][] cArray = new Circle[col][row]; //Declare array
Circle circle = new Circle(0,0);
public CircleGrid()
{
ifRed = 1;
notIfRed = 0;
int redCircles = 0;
int yellowCircles = 0;
ifEmpty = true;
addMouseListene r(this);
setLayout(new GridLayout(6,7) );
for (int i = 0; i < col; i++)
{
for (int h = 0; h < row; h++)
{
cArray[i][h] = new Circle(i,h);
this.add(cArray[i][h]);
}
}
}
[/code]
And the Circle class
[code=java]
class Circle extends JPanel
{
int rowNum, colNum;
boolean occupied;
String colour;
public Circle(int r, int c)
{
rowNum = r;
colNum = c;
occupied = false;
}
public int getRow()
{
return rowNum;
}
public int getCol()
{
return colNum;
}
[/code]
My JPanel (gameCenter) adds the CircleGrid() in the main class.
When I click on the tips of the ovals it counts it as 22 clicks instead of (and which should be) one.
Any help would be immensely appreciated.
Thank you so much in advance.
I am trying to display 42 ovals (connect 4) on JPanel but it seems to display a huge white box at the top of the panel and the tips os 7 ovals and the rest of the JPanel is blue (the background colour is set to blue).
My CircleGrid class:
[code=java]
public class CircleGrid extends JPanel implements MouseListener, MouseMotionList ener
{
int ifRed;
int notIfRed;
boolean ifEmpty;
String currentColour = "White";
final int empty = 0;
final int competitorOne = 1;
final int competitorTwo = 2;
static final int row = 6;
static final int col = 7;
Circle [][] cArray = new Circle[col][row]; //Declare array
Circle circle = new Circle(0,0);
public CircleGrid()
{
ifRed = 1;
notIfRed = 0;
int redCircles = 0;
int yellowCircles = 0;
ifEmpty = true;
addMouseListene r(this);
setLayout(new GridLayout(6,7) );
for (int i = 0; i < col; i++)
{
for (int h = 0; h < row; h++)
{
cArray[i][h] = new Circle(i,h);
this.add(cArray[i][h]);
}
}
}
[/code]
And the Circle class
[code=java]
class Circle extends JPanel
{
int rowNum, colNum;
boolean occupied;
String colour;
public Circle(int r, int c)
{
rowNum = r;
colNum = c;
occupied = false;
}
public int getRow()
{
return rowNum;
}
public int getCol()
{
return colNum;
}
[/code]
My JPanel (gameCenter) adds the CircleGrid() in the main class.
When I click on the tips of the ovals it counts it as 22 clicks instead of (and which should be) one.
Any help would be immensely appreciated.
Thank you so much in advance.
Comment