Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.alt.net!news-in-01.newsfeed.easynews.com!easynews.com!easynews!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Andrew Thompson" Subject: Re: Swing Battleship Game Message-ID: <72a0cfdde75b8@uwe> X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui In-Reply-To: <1179962208.896054.252700@w5g2000hsg.googlegroups.com> References: <1179962208.896054.252700@w5g2000hsg.googlegroups.com> Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 46 Date: Wed, 27 Apr 2011 15:34:42 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918482 96.60.20.240 (Wed, 27 Apr 2011 10:34:42 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:34:42 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:1676 To: comp.lang.java.gui KDawg44 wrote: .. >For a class I am taking I have to write a Battleship game. I am using >Swing to program a GUI and I would like to make it so that there are >two panes holding the 11x11 grid for the spots on the computer's and >the player's boards. I would like the position of the ships on the >players board to be marked somehow and I would like the user to be >able to click on the a spot on the other board to choose their shot >when it is there turn. I would like to also prevent them from >choosing the same spot twice. > >What should I use to create the boards in Swing? Layouts (same as you would use in AWT). >..What would be the >best way to try to accomplish something like this? The 11x11 grid can be made this easily.. import java.awt.*; import javax.swing.*; class LargeGrid { public static void main(String[] args) { JPanel p = new JPanel( new GridLayout(11,0) ); for (int ii=0; ii<(11*11); ii++) { p.add( new JButton("" + (ii+1)) ); } JOptionPane.showMessageDialog(null, p); } } -- Andrew Thompson http://www.athompson.info/andrew/ Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-gui/200705/1 --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24