Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2007, 06:54 PM
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
Help with Grid Layout
Hello, I'm trying to write a game in Java. The Sea Battle game where you should hit and sink the opponents ships...
It has to be in a field 10x10 squares and i had written the code for a square.
Code:
import java.awt.*; import javax.swing.*; public class Tile extends JButton{ public Tile() { super(""); } public void paintComponent (Graphics g) { g.setColor (getForeground()); } }
But i have know idea what to do next. I know I should put them in a Grid Layout, but how the hell should I program the ships?
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 09:03 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,054
hardwired is on a distinguished road
Here's an idea. Try drawing your grid in the paintComponent method of a JPanel, the sea, and drawing images of the ships in the grid cells. Keep a boolean array that matches the grid structure. You can set/change the boolean values for availability of targets. Use keyboard navigation to maneuver your ship among the cells, to rotate and to fire.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SWT Layout JavaForums Java Blogs 0 12-31-2007 05:53 PM
Object locations via grid coordinates HELP. deadman_uk New To Java 4 11-18-2007 09:32 PM
Help creating a changing grid adlb1300 New To Java 11 10-24-2007 02:41 PM
JGraph Layout Pro 1.4.0.3 levent Java Announcements 0 07-31-2007 07:43 PM
Grid Resources for Industrial Applications 5.1 levent Java Announcements 0 05-24-2007 10:57 AM


All times are GMT +3. The time now is 09:02 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org