Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making a good looking grid in Swing

 
Matthieu Saenen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, at the end of next week I need a Battleship game, but I'm stuck with making a 2d grid. I have to make something like the photo, but i don't even know how to begin on it. In the grid it are all nice squares and they are all nice ligned out, How did they do that?

http://www.imagebam.com/image/687e73241745809
ScreenShot001.jpg
[Thumbnail for ScreenShot001.jpg]
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Fix the sizes of all those squares. Try a grid layout. There are lots of layouts, which you can find about in the Java Tutorials.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use gradient painting for that colour shading. Draw multiple lines at right angles to each other. (This suggestion is instead of the layout and many squares, not in addition.)
 
Cameron Miller
Greenhorn
Posts: 13
Chrome Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Draw the background, then use two for loops to draw the grid, one for the vertical lines and one for the horizontal lines. E.g.


This would create a 10x10 grid starting at (10, 10).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic