Help for me to understand some code please
Hi,
I have placed here this copy of a message I posted in the Java Programming forum earlier today (no reply yet there). I think it may be more appropriate in this New to Java forum (as I am relatively new to Java!). My query is:-
I am trying to learn Java mainly with my interest in chess computing & website development.
I am learning through web articles on java (Sun tutorials etc).Presently I am looking at code to display a chessboard to lead on to building my own chess program (but that will be a longterm project!).I have already configured the java chess applet at LibThinkQuest, but am now looking to build chess apps/applets de novo by understanding all java coding fully if possible!
So now,I have a problem with some code from the internet to run & display a chessboard. This code (in full -ChessBoard.class) but it has a "class line" that needs some code adding to it, and I don't know what that is!
Please excuse my explanation of this (I am trying to get to grips with all the java terminology & structure!).
This is the "class line" code part that needs clarification:
private void draw8x8Board(int x,int y, int f, Graphics g){........
}
I need to know what code to insert here.These are the comments
/** draw8x8Board
* @param x first coordinate of upper left corner of chess board
* @param y second coordinate of upper left corner of chess board
* @param f side length of a single field on the board
* @param g graphics pen to be used for drawing
*/
I presume I need to declare the values of of x,y,f & Graphics g somehow?
I do not know if I need a method here or not!
(The ChessBoard class has a main method so that is alright!).
Presently the ChessBoard does not compile or run because of this lack of code here.With the right code inserted this will work & display the board!
Well I hope someone can explain how to manage this line of code for me! I look forward to a reply, thanks,
RPD
[2065 byte] By [
tR2a] at [2007-11-27 1:36:49]

futureHead
Thank you for your reply and direction to the How Stuff Works tutorial.
I have made my first stab at putting in appropriate code here, following this looping tutorial and it returned 10 errors from this!
So I need to redo this and I will keep trying and let you know when I get it to work!
I will also let you know if I cannot get this to work, but this may take
me quite some time for me to do before getting it right!
Thanks again for your help & I will let you know what progress I make
(otherwise feel free to list some example code for me!).
tR2a at 2007-7-12 0:46:43 >

Well, after quite sometime tonight I have achieved an output here-but as Scotty might say "it 's a chessboard Jim, but not as we know it!"
I checked out the looping info on several websites (& had to adjust my classpath which I had altered earlier trying unsuccessfully to install JMusic -which then stopped me compiling!).
So presently this chessboard is not a chessboard! I will continue to play with the code to somehow get a proper board. I present here my present hapless code offering and am open to suggestions (except giveup coding! LOL!). I am using a lot of trial & error to learn what & how this code does & doesn't work. Just to think I then need to colour alternate squares and add mouselistener control, coordinates, chess pieces & more features(moves etc) !
Still I have learnt something new about loops/ looping.Here is the code:-
private void draw8x8Board(int x,int y, int f, Graphics g){
for (x = 10; x <= 220; x = x + 25)
{
g.drawLine(x, 20, x, 220 );
}
for (y = 10;y<= 220; y = y+25){
g.drawLine (20, y, 220, y );
}
for (f = 10; f<=220; f = f + 10){
g.drawLine( x, y, 10,10);
}
}
What an odd board; what skill?! mmmm.......(I can't believe I'm showing this. I hope I can sort it out reasonably quickly.Anyway I'm just starting to learn some Java, and in a strange way it is a bit of fun -though it'll be out of fashion by the time I get it right!).
RPD(=tR2):mycode
tR2a at 2007-7-12 0:46:43 >
