Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1676

Re: Swing Battleship Game

From "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Subject Re: Swing Battleship Game
Message-ID <72a0cfdde75b8@uwe> (permalink)
Newsgroups comp.lang.java.gui
References <1179962208.896054.252700@w5g2000hsg.googlegroups.com>
Date 2011-04-27 15:34 +0000
Organization TDS.net

Show all headers | View raw


  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..
<sscce>
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);
   }
}
</sscce>

-- 
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

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Swing Battleship Game "KDawg44" <kdawg44@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
  Re: Swing Battleship Game "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
    Re: Swing Battleship Game "visionset" <visionset@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
      Re: Swing Battleship Game "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
        Re: Swing Battleship Game "visionset" <visionset@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
          Re: Swing Battleship Game "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
            Re: Swing Battleship Game "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
            Re: Swing Battleship Game "visionset" <visionset@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
            Re: Swing Battleship Game "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000

csiph-web