• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Greenhorn
Posts: 15
Mac Eclipse IDE Java
  • 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));

 
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.
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use GridLayout to place your buttons on the board.
 
Marshal
Posts: 69814
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and welcome to the Ranch
 
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
 
Honk if you love justice! And honk twice for tiny ads!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic