• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help Needed on Programming Exercise Chapter 3 Question 10 (The Art and Science of Java)  RSS feed

 
Darrin Altman
Greenhorn
Posts: 15
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am breaking my head trying to figure this out. If you don't have the book, I need to place a tic tac toe board in the center of my window using a single constant called BOARD_SIZE to define the height and width of the figure. I understand how to center an oval or rectangle but not centering the four lines. And the use of the single constant is confusing me also.

Here is the "run portion" (not sure if calling this as "run portion" is correct) of the original program that creates the tic tac toe board, which I am supposed to center and refine. Any help will be greatly appreciated.

add(new GLine(30, 60, 120,60));
add(new GLine(30, 90, 120, 90));
add(new GLine(60, 30, 60, 120));
add(new GLine(90, 30, 90, 120));

 
Kristjan Toots
Ranch Hand
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch!
Maybe we do have different books but I found only 9 questions in chapter 3.

Well, BOARD_SIZE could be one side of the imaginable square. Since square sides are all even, one defined constant would do the trick.
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use GridLayout to place your buttons on the board.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and welcome to the Ranch
 
Marcelo Oliveira
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darrin Altman wrote:I am breaking my head trying to figure this out. If you don't have the book, I need to place a tic tac toe board in the center of my window using a single constant called BOARD_SIZE to define the height and width of the figure. I understand how to center an oval or rectangle but not centering the four lines. And the use of the single constant is confusing me also.

Here is the "run portion" (not sure if calling this as "run portion" is correct) of the original program that creates the tic tac toe board, which I am supposed to center and refine. Any help will be greatly appreciated.

add(new GLine(30, 60, 120,60));
add(new GLine(30, 90, 120, 90));
add(new GLine(60, 30, 60, 120));
add(new GLine(90, 30, 90, 120));



Hey Darrin,

I was able to make the tic tac toe board center on the screen with the following code....

I used getWidth() and divided by 2 to get the center of the screen, then I subtracted by the BOARD_SIZE divided by 2.

http://maowebsolutions.tumblr.com/post/60805655617/the-art-and-science-of-java-exercise-solutions
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!