This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Checkerboard w/ 64 squares Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Checkerboard w/ 64 squares " Watch "Checkerboard w/ 64 squares " New topic
Author

Checkerboard w/ 64 squares

Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 73
Hello forum,

I'm working on an assignment requiring me to create a checkerboard with 64 squares. I've got three classes: A viewer, Checkerboard component, and a checkerboard which constructs the squares.

My attempt so far is to create 2 row methods in the CHeckerboard Class, one that starts a row off with a white square; the second starting with a black square

In the Checkerboard component class, I want to simply call each one four times changing the y coordinate so it lines each row up.

However, this doesn't seem to work. What am I doing wrong?

Viewer Class


Checkerboard Component Class:


Checkerboard Class
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
comment out your current CheckerBoardComponent class and replace with this to see what's happening



Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 73
Thank you. I see that the values are all being returned as 0. I hard-coded the values I'm trying to test and still renders the same.. I've included the code now with x replaced with the actual x value I'm looking for. Still prints out as all zeros

Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

Your Checkerboard constructor doesn't do anything. Passing it different values won't result in any differences in the Checkerboard objects you create.
Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 73
Ahh your right.. I wasn't using the arguments being passed..

I've fixed it and it works.. I've included the solution code for this thread's integrity:

Viewer:


Component Class:



Checkerboard class:
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

You were on the right track, it was the debugging code you posted that made me want to look at the Checkerboard class and its constructor.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Checkerboard w/ 64 squares
 
It's not a secret anymore!