• Post Reply Bookmark Topic Watch Topic
  • New Topic

The Art & Science of Java Chapter 4 Exercise 14 Checkers  RSS feed

 
M Ford
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

I'm going through CS106A(Programming Methodology) course from iTunes where in the The Art & Science of Java book associated with the course, there is an exercise called Checkers.

Below is that exercise and as you can see, I've completed the program but not as polished as I hope.

I am using Eclipse and had no Programming Knowledge prior to this course.

-------------------------------------

How do get rid of the circles or blank checkers from the white squares?

Also how do I make the checkers smaller and centred in each black squares?

Thank you guys.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using doubles for the number of rows? That is definitely an integer number. Why have you got N_Rows (which should be spelt in UPPER_CASE throughout) and columns as well? The board is square, so you always have rows and columns the same.
How are you drawing the board? Are you using the paintComponent method? In which case you would call super.paintComponent(g); as the first line of that method.
Why have you got all that GUI work in the run() method? That ought to be in the constructor of the GUI class, or a method called private void initGUI() called from the constructor.

Don’t know exactly why you are getting that problem, but check those queries and see how far you get.
 
Goran Dragutinovic
Greenhorn
Posts: 2
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The proper code is:


 
Jeremy Mazz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding this line



I tried running this code in Eclipse and I ran a println on this statement and received '0' as its output. I know this can't be correct. What is this variable supposed to be calculating. The code above doesn't have any comments. Thanks.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy Mazz wrote:I have a question regarding this line



I tried running this code in Eclipse and I ran a println on this statement and received '0' as its output. I know this can't be correct. What is this variable supposed to be calculating. The code above doesn't have any comments. Thanks.

Welcome to the Ranch.

To be honest I don't know. Looking at how it is used I guess it's supposed to be the total board width and the OP was assuming the panel was going to be wider than it was high and so the board would fill the height but would need to be centered on the width. Having said that the calculation doesn't appear to be calculating that so maybe I'm barking up the wrong tree. Without having the rest of the code so I can run it, it's hard to give further advice, sorry.

Maybe someone else here knows the question and can give a better answer.

 
Jeremy Mazz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying, the rest of the code is two posts up from my original post. I was referring to Goran Dragutinovic code.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy Mazz wrote:Thanks for replying, the rest of the code is two posts up from my original post. I was referring to Goran Dragutinovic code.


I figure that line puts the checker board in the center of the panel. hence the "getWidth()/2 -" part.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy Mazz wrote:Thanks for replying, the rest of the code is two posts up from my original post. I was referring to Goran Dragutinovic code.

Yes, I saw that. That's how I worked out it was probably being used to center the panel along the X axis. But that code is not an SSCCE and so can't be run.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!