tryin to write Connect Four

Having some problems with my code (alot actually but heres just a little bit). Everytime I call a method from the Board class (board.gameOver() etc.) it complains and I'm not sure why. It says the method is undefind

import java.applet.*;

import java.awt.*;

import java.util.*;

publicclass GameDisplayextends Appletimplements MouseListener

{

Board board;

String turn,message;

publicvoid init()

{

board =new Board();

turn ="red";

message ="";

addMouseListener(this);

}

publicvoid mouseClicked (MouseEvent me)

{

Location loc =new Location(me.getX(),me.getY());

if(loc.isValid(board) && board.isEmpty(loc))

{

if(turn.equals("red"))

{

board.add(new Piece(turn,loc.row(),loc.col()));

update();

}

elseif(turn.equals("blue"))

{

board.add(new Piece(turn,me.row(),me.col()));

update();

}

}

if(!(board.gameOver().equals("nobody")))

{

message ="Game Over! The winner is " + board.gameOver();

update();

}

}

publicvoid mouseEntered (MouseEvent me){}

publicvoid mousePressed (MouseEvent me){}

publicvoid mouseReleased (MouseEvent me){}

publicvoid mouseExited (MouseEvent me){}

publicvoid update()

{

paint(g);

}

publicvoid paint(Graphics g)

{

for(int i=0;i<board.getPieces().size();i++)

{

Piece p = board.getPieces().get(i);

g.drawImage(p.display(), p.getXloc(), p.getYloc(),null);//getX and getY have to return where to draw the thing. which means in Piece I have to figure out where they go

}

g.drawImage(board.display(), 0, 0,null);

if(!(board.gameOver().equals("nobody")))

{

g.drawString(message,0,0);

//Wait a certain amount of time

init();//Reset game

}

}

}

import java.util.*;

publicclass Board

{

Image pic;

Piece[][] board =new Piece();//something

Tool t;

Arraylist pieces;

String winner;

boolean over;

int ct;

public Board()

{

t = Toolkit.getDefaultToolkit();

pic = t.getImage(fileName);

pieces =new ArrayList();

winner ="nobody";

over =false;

ct=1;

}

publicboolean isEmpty(Location l)

{

return hold[l.row()][l.col()]==null;

}

publicboolean isEmpty(int r,int c)

{

return hold[r][c]==null;

}

publicvoid add(Piece p)

{

board[p.getRow()][p.getCol()]=p;

pieces.add(p);

}

public Image display()

{

return pic;

}

public Arraylist getPieces()

{

return pieces;

}

public String gameOver()//find out if game is over...i may have to change plus and minus

{

for (int r=0;r<pieces.size();x++)//did red win

{

Piece p = redPieces.get(r);

int row = p.row();

int col = p.col();

while(row-1>=0 && !isEmpty(row-1,col) && hold[row-1][col].getColor().equals(hold[row][col].getColor()))

{

ct++;

row--;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

while(row+1<hold.length && !isEmpty(row+1,col) && hold[row+1][col].getColor().equals(hold[row][col].getColor()))

{

ct++;

row++;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

while(col-1>=0 && !isEmpty(row,col-1) && hold[row][col-1].getColor().equals(hold[row][col].getColor()))

{

ct++;

col--;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

while(col+1<hold.length && !isEmpty(row,col+1) && hold[row][col+1].getColor().equals(hold[row][col].getColor()))

{

ct++;

col++;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

while(row+1><hold.length&&col+1><hold.length && !isEmpty(row+1,col+1) && hold[row+1][col+1].getColor().equals(hold[row][col].getColor()))

{

ct++;

col++;

row++;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

while(row+1><hold.length&&col-1>=0 && !isEmpty(row+1,col-1) && hold[row+1][col-1].getColor().equals(hold[row][col].getColor()))

{

ct++;

col--;

row++;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

while(row-1>=0&&col-1>=0 && !isEmpty(row-1,col-1) && hold[row-1][col-1].getColor().equals(hold[row][col].getColor()))

{

ct++;

col--;

row--;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

while(row-1>=0&&col+1<hold.length && !isEmpty(row-1,col+1) && hold[row-1][col+1].getColor().equals(hold[row][col].getColor()))

{

ct++;

col++;

row--;

if(ct==4 && hold[row][col].getColor().equals("red"))

winner="red";

elseif(ct==4 && hold[row][col].getColor().equals("blue"))

winner="blue";

}

ct=1;

}

return winner;

}

}

>

[12410 byte] By [JFactor2004a] at [2007-11-27 7:45:35]
# 1
Is board a java word possibly? I don't think it is
JFactor2004a at 2007-7-12 19:26:18 > top of Java-index,Java Essentials,New To Java...
# 2
> Is board a java word possibly? > ...No, board is not a reserved word in Java.
prometheuzza at 2007-7-12 19:26:18 > top of Java-index,Java Essentials,New To Java...
# 3
I would guess that you have an old version of the Board class that has none of the methods. Try cleaning the build directory (removing any *.class files) and rebuilding.~Tim
SomeoneElsea at 2007-7-12 19:26:18 > top of Java-index,Java Essentials,New To Java...
# 4
That fixed it! Ok well now other things are not being able to be "resolved to a type"...board.add(new Piece(turn,loc.row(),loc.col())); its complaining about Piece
JFactor2004a at 2007-7-12 19:26:18 > top of Java-index,Java Essentials,New To Java...
# 5
Complaining?
Hippolytea at 2007-7-12 19:26:19 > top of Java-index,Java Essentials,New To Java...
# 6
its complaining about not being able to register the type of Piece...but Piece is a class, so idk why it wouldn't accept it.
JFactor2004a at 2007-7-12 19:26:19 > top of Java-index,Java Essentials,New To Java...
# 7
nvm I fixed it, it for some reason didn't make a Piece class.
JFactor2004a at 2007-7-12 19:26:19 > top of Java-index,Java Essentials,New To Java...
# 8

Ok now I can't figure out how to get it to draw pieces. It's drawing the board just fine. Here's what I have. Now, I know that pieces are being added because I printed out i

so I know when a piece is added. It just doesn't put the image on.

public void paint(Graphics g)

{

for(int i=0;i<board.getPieces().size();i++)

{

Piece p = (Piece)((board.getPieces()).get(i));

g.drawImage(p.display(), p.getXloc(), p.getYloc(),null);

g.drawImage(p.display(),0, 0,null);//This line is to just draw a piece for debugging

}

g.drawImage(board.display(), 0, 0, null);

if(!(board.gameOver().equals("nobody")))

{

g.drawString(message,0,0);

//Wait a certain amount of time

init(); //Reset game

}

}

Here's my Piece contrusctor

import java.awt.*;

public class Piece

{

int myRow,myCol,myXloc,myYloc;

String myColor,fileName,otherFileName;

Image pic;

Toolkit t;

public Piece(String c, int x,int y)

{

myRow = x;

myCol = y;

myColor = c;

fileName = "C:\\Users\\JP\\Projects\\Connect Four\\src\\redpiece";

otherFileName = "C:\\Users\\JP\\Projects\\Connect Four\\src\\blackpiece";

t = Toolkit.getDefaultToolkit();

if(c.equals("red"))

pic = t.getImage(fileName);

else if(c.equals("blue"))

pic = t.getImage(otherFileName);

convert();

}

>

JFactor2004a at 2007-7-12 19:26:19 > top of Java-index,Java Essentials,New To Java...
# 9
Well, I thought that, maybe the way I coded it, the pieces would actually get drawn behind the board so I moved the for loops after the call to draw the board but I still can't get the pieces to show up. Anyone have any idea why?
JFactor2004a at 2007-7-12 19:26:19 > top of Java-index,Java Essentials,New To Java...