Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 4 123 ... LastLast
Results 1 to 25 of 86

Thread: Battleship GUI Program

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Battleship GUI Program

    // Programmer: Paul Adcock          //
     // Project: GUI Project    //
     // Last Modification Date: 05/10/10 //
     /* The projects makes 100 shoot buttons, though all may not be needed.  It then 
        puts them in an array and later sets the ones visible accordinly to the array size.  My
    	 if statements will keep asking user for a value between 2 and 10 till they do it.  Then I'm
    	 going to put the battleship in the array and then going to have actionEvent deal with if it's 
    	 not a hit and has a text of 0, I set them default to 0, then it changes the text of that button to an M.
    	 If they shoot there again one or more times, it changes it to an A.  If they actually hit the battleship, it changes the text to 
    	 an H, shows the number of shots, and then exits.  If they surrender, it asks them if they want to, and if they do, it shows the number of shots
    	 and then exits.  If they quit, it asks them if they want to, and if they do, it justs says a goodbye message and exits.  */
     
       import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
       import javax.swing.JFrame;
       import javax.swing.JDialog;
       import javax.swing.JPanel;
       import java.awt.Graphics;
       import javax.swing.ImageIcon;
       import java.util.*;
       import java.io.*;
       import java.awt.Component;
     
     
     
     
        public class BattleshipGUI extends JFrame 
        implements ActionListener
       { // beginning of class
        // label
          private JLabel shotsLabel, arraySizeLabel;
     
       // area where text is displayed and user would normally enter text but I have made it so the user can't alter the shot count.
          private JTextField shotsTF, arraySizeTF;
     
     
          JFrame frame;
     
     
     
       // buttons
          public JButton  shoot1B, shoot2B, shoot3B, shoot4B, shoot5B, 
          shoot6B, shoot7B, shoot8B, shoot9B, shoot10B, shoot11B, shoot12B,
          shoot13B, shoot14B, shoot15B, shoot16B, shoot17B, shoot18B, shoot19B,
          shoot20B, shoot21B, shoot22B, shoot23B, shoot24B, shoot25B, shoot26B,
          shoot27B, shoot28B, shoot29B, shoot30B, shoot31B, shoot32B, shoot33B,
          shoot34B, shoot35B, shoot36B, shoot37B, shoot38B, shoot39B, shoot40B,
          shoot41B, shoot42B, shoot43B, shoot44B, shoot45B, shoot46B, shoot47B,
          shoot48B, shoot49B, shoot50B, shoot51B, shoot52B, shoot53B, shoot54B,
          shoot55B, shoot56B, shoot57B, shoot58B, shoot59B, shoot60B, shoot61B,
          shoot62B, shoot63B, shoot64B, shoot65B, shoot66B, shoot67B, shoot68B,
          shoot69B, shoot70B, shoot71B, shoot72B, shoot73B, shoot74B, shoot75B,
          shoot76B, shoot77B, shoot78B, shoot79B, shoot80B, shoot81B, shoot82B,
          shoot83B, shoot84B, shoot85B, shoot86B, shoot87B, shoot88B, shoot89B,
          shoot90B, shoot91B, shoot92B, shoot93B, shoot94B, shoot95B, shoot96B,
          shoot97B, shoot98B, shoot99B, shoot100B, surrenderB, quitB, yesB;
     
          private static final int WIDTH = 500;
          private static final int HEIGHT = 500;
     
     
     
           public BattleshipGUI()
          { // beginning of constructor
             setTitle("Battleship Game");
             Container pane = getContentPane();
             pane.setLayout(new GridLayout(11, 11));
     
                	// makes Label for shots
             shotsLabel = new JLabel("Shots: ",
                                      SwingConstants.RIGHT);
             arraySizeLabel = new JLabel("Array Size: " , 
                                      SwingConstants.RIGHT);
            // makes Text Field for shots and makes the text field non-editable
             shotsTF = new JTextField(7);      
             shotsTF.setEditable(false);
             arraySizeTF = new JTextField(2);
             arraySizeTF.setEditable(false);
     
          			// makes the buttons and sets their value initially to 0 and makes the method actionPerformed
          			// a method of the class BattleshipGUI.  I don't need individual handlers.
             shoot1B = new JButton("0");
             shoot1B.addActionListener(this);
     
             shoot2B = new JButton("0");
             shoot2B.addActionListener(this);
     
             shoot3B = new JButton("0");
             shoot3B.addActionListener(this);
     
             shoot4B = new JButton("0");
             shoot4B.addActionListener(this);
     
             shoot5B = new JButton("0");
             shoot5B.addActionListener(this);
     
             shoot6B = new JButton("0");
             shoot6B.addActionListener(this);
     
             shoot7B = new JButton("0");
             shoot7B.addActionListener(this);
     
             shoot8B = new JButton("0");
             shoot8B.addActionListener(this);
     
             shoot9B = new JButton("0");
             shoot9B.addActionListener(this);
     
             shoot10B = new JButton("0");
             shoot10B.addActionListener(this);
     
             shoot11B = new JButton("0");
             shoot11B.addActionListener(this);
     
             shoot12B = new JButton("0");
             shoot12B.addActionListener(this);
     
             shoot13B = new JButton("0");
             shoot13B.addActionListener(this);
     
             shoot14B = new JButton("0");
             shoot14B.addActionListener(this);
     
             shoot15B = new JButton("0");
             shoot15B.addActionListener(this);
     
             shoot16B = new JButton("0");
             shoot16B.addActionListener(this);
     
             shoot17B = new JButton("0");
             shoot17B.addActionListener(this);
     
             shoot18B = new JButton("0");
             shoot18B.addActionListener(this);
     
             shoot19B = new JButton("0");
             shoot19B.addActionListener(this);
     
             shoot20B = new JButton("0");
             shoot20B.addActionListener(this);
     
             shoot21B = new JButton("0");
             shoot21B.addActionListener(this);
     
             shoot22B = new JButton("0");
             shoot22B.addActionListener(this);
     
             shoot23B = new JButton("0");
             shoot23B.addActionListener(this);
     
             shoot24B = new JButton("0");
             shoot24B.addActionListener(this);
     
             shoot25B = new JButton("0");
             shoot25B.addActionListener(this);
     
             shoot26B = new JButton("0");
             shoot26B.addActionListener(this);
     
             shoot27B = new JButton("0");
             shoot27B.addActionListener(this);
     
             shoot28B = new JButton("0");
             shoot28B.addActionListener(this);
     
             shoot29B = new JButton("0");
             shoot29B.addActionListener(this);
     
             shoot30B = new JButton("0");
             shoot30B.addActionListener(this);
     
             shoot31B = new JButton("0");
             shoot31B.addActionListener(this);
     
             shoot32B = new JButton("0");
             shoot32B.addActionListener(this);
     
             shoot33B = new JButton("0");
             shoot33B.addActionListener(this);
     
             shoot34B = new JButton("0");
             shoot34B.addActionListener(this);
     
             shoot35B = new JButton("0");
             shoot35B.addActionListener(this);
     
             shoot36B = new JButton("0");
             shoot36B.addActionListener(this);
     
             shoot37B = new JButton("0");
             shoot37B.addActionListener(this);
     
             shoot38B = new JButton("0");
             shoot38B.addActionListener(this);
     
             shoot39B = new JButton("0");
             shoot39B.addActionListener(this);
     
             shoot40B = new JButton("0");
             shoot40B.addActionListener(this);
     
             shoot41B = new JButton("0");
             shoot41B.addActionListener(this);
     
             shoot42B = new JButton("0");
             shoot42B.addActionListener(this);
     
             shoot43B = new JButton("0");
             shoot43B.addActionListener(this);
     
             shoot44B = new JButton("0");
             shoot44B.addActionListener(this);
     
             shoot45B = new JButton("0");
             shoot45B.addActionListener(this);
     
             shoot46B = new JButton("0");
             shoot46B.addActionListener(this);
     
             shoot47B = new JButton("0");
             shoot47B.addActionListener(this);
     
             shoot48B = new JButton("0");
             shoot48B.addActionListener(this);
     
             shoot49B = new JButton("0");
             shoot49B.addActionListener(this);
     
             shoot50B = new JButton("0");
             shoot50B.addActionListener(this);
     
             shoot51B = new JButton("0");
             shoot51B.addActionListener(this);
     
             shoot52B = new JButton("0");
             shoot52B.addActionListener(this);
     
             shoot53B = new JButton("0");
             shoot53B.addActionListener(this);
     
             shoot54B = new JButton("0");
             shoot54B.addActionListener(this);
     
             shoot55B = new JButton("0");
             shoot55B.addActionListener(this);
     
             shoot56B = new JButton("0");
             shoot56B.addActionListener(this);
     
             shoot57B = new JButton("0");
             shoot57B.addActionListener(this);
     
             shoot58B = new JButton("0");
             shoot58B.addActionListener(this);
     
             shoot59B = new JButton("0");
             shoot59B.addActionListener(this);
     
             shoot60B = new JButton("0");
             shoot60B.addActionListener(this);
     
             shoot61B = new JButton("0");
             shoot61B.addActionListener(this);
     
             shoot62B = new JButton("0");
             shoot62B.addActionListener(this);
     
             shoot63B = new JButton("0");
             shoot63B.addActionListener(this);
     
             shoot64B = new JButton("0");
             shoot64B.addActionListener(this);
     
             shoot65B = new JButton("0");
             shoot65B.addActionListener(this);
     
             shoot66B = new JButton("0");
             shoot66B.addActionListener(this);
     
             shoot67B = new JButton("0");
             shoot67B.addActionListener(this);
     
             shoot68B = new JButton("0");
             shoot68B.addActionListener(this);
     
             shoot69B = new JButton("0");
             shoot69B.addActionListener(this);
     
             shoot70B = new JButton("0");
             shoot70B.addActionListener(this);
     
             shoot71B = new JButton("0");
             shoot71B.addActionListener(this);
     
             shoot72B = new JButton("0");
             shoot72B.addActionListener(this);
     
             shoot73B = new JButton("0");
             shoot73B.addActionListener(this);
     
             shoot74B = new JButton("0");
             shoot74B.addActionListener(this);
     
             shoot75B = new JButton("0");
             shoot75B.addActionListener(this);
     
             shoot76B = new JButton("0");
             shoot76B.addActionListener(this);
     
             shoot77B = new JButton("0");
             shoot77B.addActionListener(this);
     
             shoot78B = new JButton("0");
             shoot78B.addActionListener(this);
     
             shoot79B = new JButton("0");
             shoot79B.addActionListener(this);
     
             shoot80B = new JButton("0");
             shoot80B.addActionListener(this);
     
             shoot81B = new JButton("0");
             shoot81B.addActionListener(this);
     
             shoot82B = new JButton("0");
             shoot82B.addActionListener(this);
     
             shoot83B = new JButton("0");
             shoot83B.addActionListener(this);
     
             shoot84B = new JButton("0");
             shoot84B.addActionListener(this);
     
             shoot85B = new JButton("0");
             shoot85B.addActionListener(this);
     
             shoot86B = new JButton("0");
             shoot86B.addActionListener(this);
     
             shoot87B = new JButton("0");
             shoot87B.addActionListener(this);
     
             shoot88B = new JButton("0");
             shoot88B.addActionListener(this);
     
             shoot89B = new JButton("0");
             shoot89B.addActionListener(this);
     
             shoot90B = new JButton("0");
             shoot90B.addActionListener(this);
     
             shoot91B = new JButton("0");
             shoot91B.addActionListener(this);
     
             shoot92B = new JButton("0");
             shoot92B.addActionListener(this);
     
             shoot93B = new JButton("0");
             shoot93B.addActionListener(this);
     
             shoot94B = new JButton("0");
             shoot94B.addActionListener(this);
     
             shoot95B = new JButton("0");
             shoot95B.addActionListener(this);
     
             shoot96B = new JButton("0");
             shoot96B.addActionListener(this);
     
             shoot97B = new JButton("0");
             shoot97B.addActionListener(this);
     
             shoot98B = new JButton("0");
             shoot98B.addActionListener(this);
     
             shoot99B = new JButton("0");
             shoot99B.addActionListener(this);
     
             shoot100B = new JButton("0");
             shoot100B.addActionListener(this);
     
             surrenderB = new JButton("Surrender");
             surrenderB.addActionListener(this);
     
             quitB = new JButton("Quit");
             quitB.addActionListener(this);
     
          // n is the size of the grid
             int n = 0;
             String gridSizeStr, outputStr;
             boolean isInRange = false;
          // while loop and boolean allow user to keep entering int values till n is between 2 and 10.  Also, it makes certain 
          // buttons part of the array of buttons so that I can make it in a square shape, though I also need to take care of the 
          // set visible thing, which I have, and also so I can place the battleship in the array and later use actionListeners to
          // change the text to either a M, an A, or a H.  
     
          // actually puts the buttons in the interface and on the pane
             pane.add(shoot1B);
             pane.add(shoot2B);
             pane.add(shoot3B);
             pane.add(shoot4B);
             pane.add(shoot5B);
             pane.add(shoot6B);
             pane.add(shoot7B);
             pane.add(shoot8B);
             pane.add(shoot9B);
             pane.add(shoot10B);
             pane.add(shoot11B);
             pane.add(shoot12B);
             pane.add(shoot13B);
             pane.add(shoot14B);
             pane.add(shoot15B);
             pane.add(shoot16B);
             pane.add(shoot17B);
             pane.add(shoot18B);
             pane.add(shoot19B);
             pane.add(shoot20B);
             pane.add(shoot21B);
             pane.add(shoot22B);
             pane.add(shoot23B);
             pane.add(shoot24B);
             pane.add(shoot25B);
             pane.add(shoot26B);
             pane.add(shoot27B);
             pane.add(shoot28B);
             pane.add(shoot29B);
             pane.add(shoot30B);
             pane.add(shoot31B);
             pane.add(shoot32B);
             pane.add(shoot33B);
             pane.add(shoot34B);
             pane.add(shoot35B);
             pane.add(shoot36B);
             pane.add(shoot37B);
             pane.add(shoot38B);
             pane.add(shoot39B);
             pane.add(shoot40B);
             pane.add(shoot41B);
             pane.add(shoot42B);
             pane.add(shoot43B);
             pane.add(shoot44B);
             pane.add(shoot45B);
             pane.add(shoot46B);
             pane.add(shoot47B);
             pane.add(shoot48B);
             pane.add(shoot49B);
             pane.add(shoot50B);
             pane.add(shoot51B);
             pane.add(shoot52B);
             pane.add(shoot53B);
             pane.add(shoot54B);
             pane.add(shoot55B);
             pane.add(shoot56B);
             pane.add(shoot57B);
             pane.add(shoot58B);
             pane.add(shoot59B);
             pane.add(shoot60B);
             pane.add(shoot61B);
             pane.add(shoot62B);
             pane.add(shoot63B);
             pane.add(shoot64B);
             pane.add(shoot65B);
             pane.add(shoot66B);
             pane.add(shoot67B);
             pane.add(shoot68B);
             pane.add(shoot69B);
             pane.add(shoot70B);
             pane.add(shoot71B);
             pane.add(shoot72B);
             pane.add(shoot73B);
             pane.add(shoot74B);
             pane.add(shoot75B);
             pane.add(shoot76B);
             pane.add(shoot77B);
             pane.add(shoot78B);
             pane.add(shoot79B);
             pane.add(shoot80B);
             pane.add(shoot81B);
             pane.add(shoot82B);
             pane.add(shoot83B);
             pane.add(shoot84B);
             pane.add(shoot85B);
             pane.add(shoot86B);
             pane.add(shoot87B);
             pane.add(shoot88B);
             pane.add(shoot89B);
             pane.add(shoot90B);
             pane.add(shoot91B);
             pane.add(shoot92B);
             pane.add(shoot93B);
             pane.add(shoot94B);
             pane.add(shoot95B);
             pane.add(shoot96B);
             pane.add(shoot97B);
             pane.add(shoot98B);
             pane.add(shoot99B);
             pane.add(shoot100B);
             pane.add(surrenderB);
             pane.add(quitB);
             pane.add(shotsLabel);
             pane.add(shotsTF);
             pane.add(arraySizeLabel);
             pane.add(arraySizeTF);
     
             shotsTF.setText("0");
             boolean isValid = false;
     
             while (isValid == false)
             { // beginning of while
                try
                { // beginning of try
                   gridSizeStr = JOptionPane.showInputDialog("Enter the size of the grid:");
                   n = Integer.parseInt(gridSizeStr);
     
                   Integer storeValue;
     
                   storeValue = n;
     
                   arraySizeTF.setText(storeValue.toString());
     
                   if (n < 2)
                      throw new MyTooSmallException();
     
                   if (n > 10)
                      throw new MyTooBigException();
     
                   isValid = true;
     
                } // end of try
     
                    catch ( MyTooSmallException mtse)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + " 2 and is no greater than 10. " +"\n " + mtse.toString() );
     
                   } // end of catch
     
                    catch ( MyTooBigException mtbe)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + "2 and is no greater than 10. " +"\n " + mtbe.toString() );
     
                   } // end of catch
     
     
                    catch (NumberFormatException nfeRef)          //Line 13
                   { // beginning of catch
                      JOptionPane.showMessageDialog(null,
                         "Enter an integer.  Exception "
                         + nfeRef.toString(),
                         "NumberFormatException",
                         JOptionPane.ERROR_MESSAGE);       //Line 14
                   } // end of catch
     
             } // end of while 
     
     
             if (n >=2 && n <= 10)
             { // beginning of if				
     
     
               JButton[][] arrayOfButtons = new JButton[n][n];
     
     
                for (int i = 0; i < arrayOfButtons.length; i++)
                {
                   for (int j = 0; j < arrayOfButtons[i].length; j++)
                      arrayOfButtons[i][j] = new JButton();
                }
     
     
    			   char [][] charArray = new char[n][n];
             for ( int x = 0; x < charArray.length; x++)
                {
                   for ( int y = 0; y < charArray[x].length; y++)
                      charArray[x][y] = '0';
                }
     
     
     
                	 // hopefully these two for loop sets will make them parallel arrays
     
     
     
                if ( n == 2)
                { // beginning of if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
     
                } // end of if
                else if (n == 3)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
     
                } // end of else if
                else if (n == 4)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
     
                } // end of else if
                else if (n ==5)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
     
                } // end of else if
                else if (n == 6)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
     
                } // end of else if
     
                else if (n == 7)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
     
                } // end of else if
     
                else if (n == 8)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[0][7] = shoot8B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[1][7] = shoot18B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[2][7] = shoot28B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[3][7] = shoot38B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[4][7] = shoot48B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[5][7] = shoot58B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
                   arrayOfButtons[6][7] = shoot68B;
                   arrayOfButtons[7][0] = shoot71B;
                   arrayOfButtons[7][1] = shoot72B;
                   arrayOfButtons[7][2] = shoot73B;
                   arrayOfButtons[7][3] = shoot74B;
                   arrayOfButtons[7][4] = shoot75B;
                   arrayOfButtons[7][5] = shoot76B;
                   arrayOfButtons[7][6] = shoot77B;
                   arrayOfButtons[7][7] = shoot78B;
     
                } // end of else if
     
                else if (n == 9)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[0][7] = shoot8B;
                   arrayOfButtons[0][8] = shoot9B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[1][7] = shoot18B;
                   arrayOfButtons[1][8] = shoot19B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[2][7] = shoot28B;
                   arrayOfButtons[2][8] = shoot29B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[3][7] = shoot38B;
                   arrayOfButtons[3][8] = shoot39B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[4][7] = shoot48B;
                   arrayOfButtons[4][8] = shoot49B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[5][7] = shoot58B;
                   arrayOfButtons[5][8] = shoot59B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
                   arrayOfButtons[6][7] = shoot68B;
                   arrayOfButtons[6][8] = shoot69B;
                   arrayOfButtons[7][0] = shoot71B;
                   arrayOfButtons[7][1] = shoot72B;
                   arrayOfButtons[7][2] = shoot73B;
                   arrayOfButtons[7][3] = shoot74B;
                   arrayOfButtons[7][4] = shoot75B;
                   arrayOfButtons[7][5] = shoot76B;
                   arrayOfButtons[7][6] = shoot77B;
                   arrayOfButtons[7][7] = shoot78B;
                   arrayOfButtons[7][8] = shoot79B;
                   arrayOfButtons[8][0] = shoot81B;
                   arrayOfButtons[8][1] = shoot82B;
                   arrayOfButtons[8][2] = shoot83B;
                   arrayOfButtons[8][3] = shoot84B;
                   arrayOfButtons[8][4] = shoot85B;
                   arrayOfButtons[8][5] = shoot86B;
                   arrayOfButtons[8][6] = shoot87B;
                   arrayOfButtons[8][7] = shoot88B;
                   arrayOfButtons[8][8] = shoot89B;
     
                } // end of else if
                else 
                { // beginning of else
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[0][7] = shoot8B;
                   arrayOfButtons[0][8] = shoot9B;
                   arrayOfButtons[0][9] = shoot10B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[1][7] = shoot18B;
                   arrayOfButtons[1][8] = shoot19B;
                   arrayOfButtons[1][9] = shoot20B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[2][7] = shoot28B;
                   arrayOfButtons[2][8] = shoot29B;
                   arrayOfButtons[2][9] = shoot30B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[3][7] = shoot38B;
                   arrayOfButtons[3][8] = shoot39B;
                   arrayOfButtons[3][9] = shoot40B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[4][7] = shoot48B;
                   arrayOfButtons[4][8] = shoot49B;
                   arrayOfButtons[4][9] = shoot50B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[5][7] = shoot58B;
                   arrayOfButtons[5][8] = shoot59B;
                   arrayOfButtons[5][9] = shoot60B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
                   arrayOfButtons[6][7] = shoot68B;
                   arrayOfButtons[6][8] = shoot69B;
                   arrayOfButtons[6][9] = shoot70B;
                   arrayOfButtons[7][0] = shoot71B;
                   arrayOfButtons[7][1] = shoot72B;
                   arrayOfButtons[7][2] = shoot73B;
                   arrayOfButtons[7][3] = shoot74B;
                   arrayOfButtons[7][4] = shoot75B;
                   arrayOfButtons[7][5] = shoot76B;
                   arrayOfButtons[7][6] = shoot77B;
                   arrayOfButtons[7][7] = shoot78B;
                   arrayOfButtons[7][8] = shoot79B;
                   arrayOfButtons[7][9] = shoot80B;
                   arrayOfButtons[8][0] = shoot81B;
                   arrayOfButtons[8][1] = shoot82B;
                   arrayOfButtons[8][2] = shoot83B;
                   arrayOfButtons[8][3] = shoot84B;
                   arrayOfButtons[8][4] = shoot85B;
                   arrayOfButtons[8][5] = shoot86B;
                   arrayOfButtons[8][6] = shoot87B;
                   arrayOfButtons[8][7] = shoot88B;
                   arrayOfButtons[8][8] = shoot89B;
                   arrayOfButtons[8][9] = shoot90B;
                   arrayOfButtons[9][0] = shoot91B;
                   arrayOfButtons[9][1] = shoot92B;
                   arrayOfButtons[9][2] = shoot93B;
                   arrayOfButtons[9][3] = shoot94B;
                   arrayOfButtons[9][4] = shoot95B;
                   arrayOfButtons[9][5] = shoot96B;
                   arrayOfButtons[9][6] = shoot97B;
                   arrayOfButtons[9][7] = shoot98B;
                   arrayOfButtons[9][8] = shoot99B;
                   arrayOfButtons[9][9] = shoot100B;
     
     
     
     
     
                } // end of else
     
     
     
             } // end of if      
     
     
     
     
          // makes an n by n grid
             if ( n == 2)
             {  // beginning of if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(false);
                shoot4B.setVisible(false);
                shoot5B.setVisible(false);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(false);
                shoot14B.setVisible(false);
                shoot15B.setVisible(false);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(false);
                shoot22B.setVisible(false);
                shoot23B.setVisible(false);
                shoot24B.setVisible(false);
                shoot25B.setVisible(false);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(false);
                shoot32B.setVisible(false);
                shoot33B.setVisible(false);
                shoot34B.setVisible(false);
                shoot35B.setVisible(false);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(false);
                shoot42B.setVisible(false);
                shoot43B.setVisible(false);
                shoot44B.setVisible(false);
                shoot45B.setVisible(false);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of if
     
             else if (n == 3)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(false);
                shoot5B.setVisible(false);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(false);
                shoot15B.setVisible(false);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(false);
                shoot25B.setVisible(false);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(false);
                shoot32B.setVisible(false);
                shoot33B.setVisible(false);
                shoot34B.setVisible(false);
                shoot35B.setVisible(false);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(false);
                shoot42B.setVisible(false);
                shoot43B.setVisible(false);
                shoot44B.setVisible(false);
                shoot45B.setVisible(false);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 4)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(false);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(false);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(false);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(false);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(false);
                shoot42B.setVisible(false);
                shoot43B.setVisible(false);
                shoot44B.setVisible(false);
                shoot45B.setVisible(false);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 5)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 6)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 7)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 8)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(true);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(true);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(true);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(true);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(true);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(true);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(true);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(true);
                shoot72B.setVisible(true);
                shoot73B.setVisible(true);
                shoot74B.setVisible(true);
                shoot75B.setVisible(true);
                shoot76B.setVisible(true);
                shoot77B.setVisible(true);
                shoot78B.setVisible(true);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 9)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(true);
                shoot9B.setVisible(true);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(true);
                shoot19B.setVisible(true);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(true);
                shoot29B.setVisible(true);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(true);
                shoot39B.setVisible(true);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(true);
                shoot49B.setVisible(true);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(true);
                shoot59B.setVisible(true);
                shoot60B.setVisible(false);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(true);
                shoot69B.setVisible(true);
                shoot70B.setVisible(false);
                shoot71B.setVisible(true);
                shoot72B.setVisible(true);
                shoot73B.setVisible(true);
                shoot74B.setVisible(true);
                shoot75B.setVisible(true);
                shoot76B.setVisible(true);
                shoot77B.setVisible(true);
                shoot78B.setVisible(true);
                shoot79B.setVisible(true);
                shoot80B.setVisible(false);
                shoot81B.setVisible(true);
                shoot82B.setVisible(true);
                shoot83B.setVisible(true);
                shoot84B.setVisible(true);
                shoot85B.setVisible(true);
                shoot86B.setVisible(true);
                shoot87B.setVisible(true);
                shoot88B.setVisible(true);
                shoot89B.setVisible(true);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else
             { // beginning of else
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(true);
                shoot9B.setVisible(true);
                shoot10B.setVisible(true);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(true);
                shoot19B.setVisible(true);
                shoot20B.setVisible(true);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(true);
                shoot29B.setVisible(true);
                shoot30B.setVisible(true);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(true);
                shoot39B.setVisible(true);
                shoot40B.setVisible(true);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(true);
                shoot49B.setVisible(true);
                shoot50B.setVisible(true);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(true);
                shoot59B.setVisible(true);
                shoot60B.setVisible(true);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(true);
                shoot69B.setVisible(true);
                shoot70B.setVisible(true);
                shoot71B.setVisible(true);
                shoot72B.setVisible(true);
                shoot73B.setVisible(true);
                shoot74B.setVisible(true);
                shoot75B.setVisible(true);
                shoot76B.setVisible(true);
                shoot77B.setVisible(true);
                shoot78B.setVisible(true);
                shoot79B.setVisible(true);
                shoot80B.setVisible(true);
                shoot81B.setVisible(true);
                shoot82B.setVisible(true);
                shoot83B.setVisible(true);
                shoot84B.setVisible(true);
                shoot85B.setVisible(true);
                shoot86B.setVisible(true);
                shoot87B.setVisible(true);
                shoot88B.setVisible(true);
                shoot89B.setVisible(true);
                shoot90B.setVisible(true);
                shoot91B.setVisible(true);
                shoot92B.setVisible(true);
                shoot93B.setVisible(true);
                shoot94B.setVisible(true);
                shoot95B.setVisible(true);
                shoot96B.setVisible(true);
                shoot97B.setVisible(true);
                shoot98B.setVisible(true);
                shoot99B.setVisible(true);
                shoot100B.setVisible(true);
             } // end of else
     
     
             quitB.setSize(80, 30);
             setSize(WIDTH, HEIGHT);
             setVisible(true);
             setDefaultCloseOperation(EXIT_ON_CLOSE);
     
     
          } // end of constructor
     
           public static void main(String[] args)
          { // beginning of main
             BattleshipGUI refVar = new BattleshipGUI();
     
          } // end of main
     
       	// this method handles the buttons.  
           public void actionPerformed(ActionEvent e)
          { // beginning of method
             String outputStr2, outputStr3, outputStr4, outputStr5, outputStr6;
             String outputStrM, outputStrA, outputStrAA;
             outputStrM = "Miss";
             outputStrA = "Already shot there";
             outputStrAA = "I told you that you already shot there";
     
             outputStr2 = "Are you sure you want to quit? ";
             outputStr3 = "You Quit.";
             outputStr4 = "Ok don't quit then." ;
             outputStr5 = "Thought not.";
             outputStr6 = "You surrendered.";
     
     
             int i, j, x,y;
             x = 0;
             i = 0;
             y = 0;
             j = 0;
             int v;
             v = 0;
             IntClass getN;
             int shots =  Integer.parseInt(shotsTF.getText());
     
     
     
             int w = Integer.parseInt(arraySizeTF.getText());
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
                     placeBattleship(charArray); 
     
     
             int num, num2;
             num = 0;
             num2 = 0;
     
             Integer tries;
             Integer tries2;
             Integer tries3;
             Integer tries4;
     
             tries = shots;
             tries2 = shots;
             tries3 = shots;
             tries4 = shots;
     
             if (e.getActionCommand().equals("Quit"))
             { // beginning of if
                Object[] options = {"Yes",
                        "Continue Playing"};
     
                int n = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Quit?",
                   "Quit",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options,     options[0]); 
             // creates Yes and Continue playing butons buttons.
             		// if Yee button is clicked, sends output "You quit." as heading and sends a message "Adiós!" and exits when 
             		// user clicks OK on dialog box
                if (n == JOptionPane.YES_OPTION) 
                { // beginning of if
                   JOptionPane.showMessageDialog(null,"Adiós!", outputStr3,  JOptionPane.PLAIN_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // Continue Playing, sends title "Ok don't quit then." and the message "Whatever." and takes the user back to the grid.
                else if (n == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null,"Whatever.",  outputStr4,  JOptionPane.PLAIN_MESSAGE);
                } // end of else if
     
             } // end of if
     
             else if (e.getActionCommand().equals("Surrender"))
             { // beginning of else if
                shots = shots + 1;
                Object[] options2 = {"Yes",
                        "No, I have not yet begun to fight!"};
                int p = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Surrender?",
                   "Surrender?",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options2,   options2[0]); 
             // creates Yes and No, I have not yet begun to fight! butons .
             		// if Yes button is clicked, sends output "You surrendered." as heading and sends a message "It took you [number of shots]
             		// shots!" and exits when user clicks OK on dialog box
                if (p == JOptionPane.YES_OPTION) 
                { // beginning of if
                // code for showing grid
                    arrayOfButtons[i][j].setText("B");
                   JOptionPane.showMessageDialog(null, "You took "  + shotsTF.getText() + " shots" , outputStr6, JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // "No button", sends output "Thought not." and the title "You didn't surrender." and takes the user back to the grid.
                else if (p == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null, outputStr5, "You didn't surrender." , JOptionPane.PLAIN_MESSAGE);
                } // end of else if
             } // end of else if
     
     
             else if (e.getActionCommand().equals("0"))
             { // beginning of else if
                int K;
                int t;
                String r;
             // I tried with the shots.  This assignment is very difficult.  
     
     
                if (  Fire(charArray, x, y) == 'H')
                { // beginning of if
                   String outputStr7;
                   arrayOfButtons[i][j].setText("H");  // changes text on button to H
                   shots = shots + 1;
                   tries = new Integer(shots);
     
                   shotsTF.setText(tries.toString());
     
     
                   outputStr7 = "You sank my battleship. " + "\n" + "You sank my battleship in" + shotsTF.getText() + "tries";
                   JOptionPane.showMessageDialog(null, outputStr7 , "You win!", +  JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                }// end of if
     
                else 
                { // beginning of else
                   JOptionPane.showMessageDialog(null, outputStrM , "You missed!", +  JOptionPane.INFORMATION_MESSAGE);
                   arrayOfButtons[i][j].setText("M"); // changes text on button to M
                   shots = shots + 1;
                   tries2 = new Integer(shots);
                   shotsTF.setText(tries2.toString());
     
                } // end of else
             } // end of else if 
                   // does this if text on button hit is M.
             else if (e.getActionCommand().equals("M"))
             { // beginning of else if
                shots = shots + 1;
                tries3 = new Integer(shots);
                shotsTF.setText(tries3.toString());
     
                JOptionPane.showMessageDialog(null, outputStrA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                arrayOfButtons[i][j].setText("A"); // changes text on button to A
             } // end of else if
                   // does this if text on button hit is A
             else if (e.getActionCommand().equals("A"))
             { // beginning of else if
                shots = shots + 1;
                tries4 = new Integer(shots);
                shotsTF.setText(tries4.toString());
     
                JOptionPane.showMessageDialog(null, outputStrAA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                arrayOfButtons[i][j].setText("A"); // changes text, sorta, on button to A
             } // end of else if
     
          } // end of method
          // the method placeBattleship, places the battleship by randomly choosing a
       // row and column coordinate and storing a 'B' there.  The 'B' is not displayed to 
       // the user unless the user hits the surrender button.  It takes the array as a parameter and 
       // should return nothing.  This method sets the location of the battleship.
     
           private static void placeBattleship(char charArray[][])
          {
             int valueOne, valueTwo;
             char B;
             valueOne= (int) ( 1 + (Math.random() * charArray.length - 1 )); 
             valueTwo = (int) ( 1 + (Math.random() * charArray.length - 1));
             charArray[valueOne][valueTwo] = 'B';
          } //end of method placeBattleship
           public static char Fire(char charArray[][], int x, int y)
          { // beginning of method Fire
             char A;
             char M;
             char H;
     
     
                   // IntClass intShotObj = new IntClass(0);  this would be necessary if I needed to use IntClass
             // to somehow get the value of shots for Miss and Already Shot.
            // IntClass intShotObj2 = new IntClass();
             if (charArray[x][y] == 'B')  // if battleship is hit return H and end game
             { // beginning of if statement
                charArray[x][y] = 'H';
     
     
                return ('H');
     
             } // end of if statement
     
             else if (charArray[x][y] == 'M')  // this is else if 
                                              // because it could also 
                                              // be just a miss.
     
             { // beginning of else if statement
     
                charArray[x][y] = 'A';
     
                return ('A');
             } // end of else if statement
     
             else if (charArray[x][y] == 'A') // makes sure it won't set an A to an M again.
             { // beginning of else if  
     
                charArray[x][y] = 'A';
              //   intShotObj.addToNum(1);  This would be used to add one to get
              // intShotObj to get from its original value and keep adding one to it till
              // I hit the battleship.  I still don't know how to do that, but I found a better way.
                return ('A');
             } // end of else if
             else
     
             { // beginning of else statement
                charArray[x][y] = 'M'; 
                return ('M');                                          
             } // end of else statement
          } // end of method fire
     
     
       } // end of program

    I can't get to compile. The two arrays need to somehow get into actionPerformed.

    I thought of possibly having also something like
    if (shoot1B.isSelected() == true)
    charArray[x][y];
    x = 0;
    y = 0;
    Last edited by javapenguin; August 23rd, 2010 at 10:24 PM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Battleship GUI Program

    umm... wow. Have you thought about using loops to create the buttons? That would drastically reduce the amount of code you have.

    for(int i = 0; i < 10; i++)
    {
         for (int j = 0; j < 10; j++)
         {
              // setup one button in here and store it into an array of buttons.
              buttons[i][j] = new Button(i + " " + j);
         }
    }

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    javapenguin (June 3rd, 2010)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    I can't get to compile
    Please copy and paste error messages here.

  5. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    I know that it needs to get the arrays into the method actionPerformed. I thought of an idea, but will this work?

     
     public static JButton [][] getStupidArray (JButton arrayOfButtons[][], int i, int j)
          {
             for ( i = 0; i < arrayOfButtons.length; i++)
             {
                for ( j = 0; j < arrayOfButtons[i].length; j++)
                   arrayOfButtons[i][j].setText("0");
             }
             return arrayOfButtons[][]
          }
     
           public static char[][] getStupidArray2 (char charArray[][], int x, int y)
          {
             for ( x = 0; x < charArray.length; x++)
             {
                for ( y = 0; y < charArray[x].length; y++)
                   charArray[x][y] = '0';
             }
             return  (charArray[][]);
          }
    and calling them in actionPerformed like this:
     JButton arrayOfButtons[][] = getStupidArray(arrayOfButtons, i, j) ;
     
             char charArray[][] = getStupidArray2(charArray, x, y);
    I gave the method that name because this part of getting it to recognize the arrays has taken many, many, many hours. And it still won't quite work.

    I have a feeling that I'm very close, however.
    Last edited by helloworld922; June 4th, 2010 at 07:12 PM. Reason: please use [code] tags

  6. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Lightbulb Re: Battleship GUI Program

    Quote Originally Posted by helloworld922 View Post
    umm... wow. Have you thought about using loops to create the buttons? That would drastically reduce the amount of code you have.

    for(int i = 0; i < 10; i++)
    {
         for (int j = 0; j < 10; j++)
         {
              // setup one button in here and store it into an array of buttons.
              buttons[i][j] = new Button(i + " " + j);
         }
    }
    Well, the slight problem I find with trying that is that the user selects the array size 2-10.

    if i > array.length, it will throw an ArrayOutOfBoundsException.

    However, what would this do:

      Container pane = getContentPane();
     
    gridSizeStr = JOptionPane.showInputDialog("Enter the size of the grid:");
                   n = Integer.parseInt(gridSizeStr);
     
    JButton [][] buttons = new JButton[n][n];
     
    for (int i = 0; i < buttons.length; i++)
    {
    for (int j = 0; j < buttons[i].length; j++)
    buttons[i][j] = new JButton("0");
    buttons[i][j].addActionListener(this);
    buttons[i][j].setVisible(true);
    pane.add(buttons[i][j]);
    }

    But what about shoot1-100B? Don't those still have to be declared as reference variables of class JButton and set to values in the array?

    If not, then what do I need to do to get my two arrays into the actionPerformd method?
    Last edited by helloworld922; June 4th, 2010 at 07:12 PM. Reason: please use [code] tags

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    what would this do
    Is that a logic question or a syntax problem? For the latter best way to find out is put it in a source and compile it.

    shoot1-100B
    What is that?

    The variable buttons has to be declared somewhere that it can be seen by those that need to use it. Inside a method means that it will go away when the method exits.

  8. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (June 3rd, 2010)

  9. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by helloworld922 View Post
    umm... wow. Have you thought about using loops to create the buttons? That would drastically reduce the amount of code you have.

    for(int i = 0; i < 10; i++)
    {
         for (int j = 0; j < 10; j++)
         {
              // setup one button in here and store it into an array of buttons.
              buttons[i][j] = new Button(i + " " + j);
         }
    }
    Quote Originally Posted by Norm View Post
    Is that a logic question or a syntax problem? For the latter best way to find out is put it in a source and compile it.


    What is that?

    The variable buttons has to be declared somewhere that it can be seen by those that need to use it. Inside a method means that it will go away when the method exits.
    I found it does reduce the amount of code, but doesn't create an n by n grid unless n = 10 and it requires an extra set of { after the j for loop.

    If I could get it to be a neat grid, I could get rid of about 1600 lines of code, otherwise I'll have to keep it to keep the right formatting.

  10. #8
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by Norm View Post
    Please copy and paste error messages here.
    BattleshipGUI.java:2222: '.class' expected
    }
    ^
    BattleshipGUI.java:2224: illegal start of expression
    public static char[][] getStupidArray2 (char charArray[][], int x, int y)
    ^
    BattleshipGUI.java:2224: ';' expected
    public static char[][] getStupidArray2 (char charArray[][], int x, int y)
    ^
    BattleshipGUI.java:2224: ';' expected
    public static char[][] getStupidArray2 (char charArray[][], int x, int y)
    ^
    BattleshipGUI.java:2224: <identifier> expected
    public static char[][] getStupidArray2 (char charArray[][], int x, int y)
    ^
    BattleshipGUI.java:2224: not a statement
    public static char[][] getStupidArray2 (char charArray[][], int x, int y)
    ^
    BattleshipGUI.java:2224: ';' expected
    public static char[][] getStupidArray2 (char charArray[][], int x, int y)
    ^
    BattleshipGUI.java:2224: ';' expected
    public static char[][] getStupidArray2 (char charArray[][], int x, int y)
    ^
    BattleshipGUI.java:2231: illegal start of expression
    return (charArray[][]);
    ^
    BattleshipGUI.java:2234: reached end of file while parsing
    } // end of program
    ^
    10 errors

    Also, won't format n by n with new code replacing very big amount shown earlier.

    for (int i = 0; i < arrayOfButtons.length; i++)
    {
    for ( int j = 0; j < arrayOfButtons[i].length; j++)
    {
    arrayOfButtons[i][j] = new JButton("0");
    arrayOfButtons[i][j].addActionListener(this);
    arrayOfButtons[i][j].setVisible(true);
    pane.add(arrayOfButtons[i][j]);

    }
    }

    replacing
    shoot1B = new JButton("0");
             shoot1B.addActionListener(this);
     
             shoot2B = new JButton("0");
             shoot2B.addActionListener(this);
     
             shoot3B = new JButton("0");
             shoot3B.addActionListener(this);
     
             shoot4B = new JButton("0");
             shoot4B.addActionListener(this);
     
             shoot5B = new JButton("0");
             shoot5B.addActionListener(this);
     
             shoot6B = new JButton("0");
             shoot6B.addActionListener(this);
     
             shoot7B = new JButton("0");
             shoot7B.addActionListener(this);
     
             shoot8B = new JButton("0");
             shoot8B.addActionListener(this);
     
             shoot9B = new JButton("0");
             shoot9B.addActionListener(this);
     
             shoot10B = new JButton("0");
             shoot10B.addActionListener(this);
     
             shoot11B = new JButton("0");
             shoot11B.addActionListener(this);
     
             shoot12B = new JButton("0");
             shoot12B.addActionListener(this);
     
             shoot13B = new JButton("0");
             shoot13B.addActionListener(this);
     
             shoot14B = new JButton("0");
             shoot14B.addActionListener(this);
     
             shoot15B = new JButton("0");
             shoot15B.addActionListener(this);
     
             shoot16B = new JButton("0");
             shoot16B.addActionListener(this);
     
             shoot17B = new JButton("0");
             shoot17B.addActionListener(this);
     
             shoot18B = new JButton("0");
             shoot18B.addActionListener(this);
     
             shoot19B = new JButton("0");
             shoot19B.addActionListener(this);
     
             shoot20B = new JButton("0");
             shoot20B.addActionListener(this);
     
             shoot21B = new JButton("0");
             shoot21B.addActionListener(this);
     
             shoot22B = new JButton("0");
             shoot22B.addActionListener(this);
     
             shoot23B = new JButton("0");
             shoot23B.addActionListener(this);
     
             shoot24B = new JButton("0");
             shoot24B.addActionListener(this);
     
             shoot25B = new JButton("0");
             shoot25B.addActionListener(this);
     
             shoot26B = new JButton("0");
             shoot26B.addActionListener(this);
     
             shoot27B = new JButton("0");
             shoot27B.addActionListener(this);
     
             shoot28B = new JButton("0");
             shoot28B.addActionListener(this);
     
             shoot29B = new JButton("0");
             shoot29B.addActionListener(this);
     
             shoot30B = new JButton("0");
             shoot30B.addActionListener(this);
     
             shoot31B = new JButton("0");
             shoot31B.addActionListener(this);
     
             shoot32B = new JButton("0");
             shoot32B.addActionListener(this);
     
             shoot33B = new JButton("0");
             shoot33B.addActionListener(this);
     
             shoot34B = new JButton("0");
             shoot34B.addActionListener(this);
     
             shoot35B = new JButton("0");
             shoot35B.addActionListener(this);
     
             shoot36B = new JButton("0");
             shoot36B.addActionListener(this);
     
             shoot37B = new JButton("0");
             shoot37B.addActionListener(this);
     
             shoot38B = new JButton("0");
             shoot38B.addActionListener(this);
     
             shoot39B = new JButton("0");
             shoot39B.addActionListener(this);
     
             shoot40B = new JButton("0");
             shoot40B.addActionListener(this);
     
             shoot41B = new JButton("0");
             shoot41B.addActionListener(this);
     
             shoot42B = new JButton("0");
             shoot42B.addActionListener(this);
     
             shoot43B = new JButton("0");
             shoot43B.addActionListener(this);
     
             shoot44B = new JButton("0");
             shoot44B.addActionListener(this);
     
             shoot45B = new JButton("0");
             shoot45B.addActionListener(this);
     
             shoot46B = new JButton("0");
             shoot46B.addActionListener(this);
     
             shoot47B = new JButton("0");
             shoot47B.addActionListener(this);
     
             shoot48B = new JButton("0");
             shoot48B.addActionListener(this);
     
             shoot49B = new JButton("0");
             shoot49B.addActionListener(this);
     
             shoot50B = new JButton("0");
             shoot50B.addActionListener(this);
     
             shoot51B = new JButton("0");
             shoot51B.addActionListener(this);
     
             shoot52B = new JButton("0");
             shoot52B.addActionListener(this);
     
             shoot53B = new JButton("0");
             shoot53B.addActionListener(this);
     
             shoot54B = new JButton("0");
             shoot54B.addActionListener(this);
     
             shoot55B = new JButton("0");
             shoot55B.addActionListener(this);
     
             shoot56B = new JButton("0");
             shoot56B.addActionListener(this);
     
             shoot57B = new JButton("0");
             shoot57B.addActionListener(this);
     
             shoot58B = new JButton("0");
             shoot58B.addActionListener(this);
     
             shoot59B = new JButton("0");
             shoot59B.addActionListener(this);
     
             shoot60B = new JButton("0");
             shoot60B.addActionListener(this);
     
             shoot61B = new JButton("0");
             shoot61B.addActionListener(this);
     
             shoot62B = new JButton("0");
             shoot62B.addActionListener(this);
     
             shoot63B = new JButton("0");
             shoot63B.addActionListener(this);
     
             shoot64B = new JButton("0");
             shoot64B.addActionListener(this);
     
             shoot65B = new JButton("0");
             shoot65B.addActionListener(this);
     
             shoot66B = new JButton("0");
             shoot66B.addActionListener(this);
     
             shoot67B = new JButton("0");
             shoot67B.addActionListener(this);
     
             shoot68B = new JButton("0");
             shoot68B.addActionListener(this);
     
             shoot69B = new JButton("0");
             shoot69B.addActionListener(this);
     
             shoot70B = new JButton("0");
             shoot70B.addActionListener(this);
     
             shoot71B = new JButton("0");
             shoot71B.addActionListener(this);
     
             shoot72B = new JButton("0");
             shoot72B.addActionListener(this);
     
             shoot73B = new JButton("0");
             shoot73B.addActionListener(this);
     
             shoot74B = new JButton("0");
             shoot74B.addActionListener(this);
     
             shoot75B = new JButton("0");
             shoot75B.addActionListener(this);
     
             shoot76B = new JButton("0");
             shoot76B.addActionListener(this);
     
             shoot77B = new JButton("0");
             shoot77B.addActionListener(this);
     
             shoot78B = new JButton("0");
             shoot78B.addActionListener(this);
     
             shoot79B = new JButton("0");
             shoot79B.addActionListener(this);
     
             shoot80B = new JButton("0");
             shoot80B.addActionListener(this);
     
             shoot81B = new JButton("0");
             shoot81B.addActionListener(this);
     
             shoot82B = new JButton("0");
             shoot82B.addActionListener(this);
     
             shoot83B = new JButton("0");
             shoot83B.addActionListener(this);
     
             shoot84B = new JButton("0");
             shoot84B.addActionListener(this);
     
             shoot85B = new JButton("0");
             shoot85B.addActionListener(this);
     
             shoot86B = new JButton("0");
             shoot86B.addActionListener(this);
     
             shoot87B = new JButton("0");
             shoot87B.addActionListener(this);
     
             shoot88B = new JButton("0");
             shoot88B.addActionListener(this);
     
             shoot89B = new JButton("0");
             shoot89B.addActionListener(this);
     
             shoot90B = new JButton("0");
             shoot90B.addActionListener(this);
     
             shoot91B = new JButton("0");
             shoot91B.addActionListener(this);
     
             shoot92B = new JButton("0");
             shoot92B.addActionListener(this);
     
             shoot93B = new JButton("0");
             shoot93B.addActionListener(this);
     
             shoot94B = new JButton("0");
             shoot94B.addActionListener(this);
     
             shoot95B = new JButton("0");
             shoot95B.addActionListener(this);
     
             shoot96B = new JButton("0");
             shoot96B.addActionListener(this);
     
             shoot97B = new JButton("0");
             shoot97B.addActionListener(this);
     
             shoot98B = new JButton("0");
             shoot98B.addActionListener(this);
     
             shoot99B = new JButton("0");
             shoot99B.addActionListener(this);
     
             shoot100B = new JButton("0");
             shoot100B.addActionListener(this); 
     
    and
     
     pane.add(shoot1B);
             pane.add(shoot2B);
             pane.add(shoot3B);
             pane.add(shoot4B);
             pane.add(shoot5B);
             pane.add(shoot6B);
             pane.add(shoot7B);
             pane.add(shoot8B);
             pane.add(shoot9B);
             pane.add(shoot10B);
             pane.add(shoot11B);
             pane.add(shoot12B);
             pane.add(shoot13B);
             pane.add(shoot14B);
             pane.add(shoot15B);
             pane.add(shoot16B);
             pane.add(shoot17B);
             pane.add(shoot18B);
             pane.add(shoot19B);
             pane.add(shoot20B);
             pane.add(shoot21B);
             pane.add(shoot22B);
             pane.add(shoot23B);
             pane.add(shoot24B);
             pane.add(shoot25B);
             pane.add(shoot26B);
             pane.add(shoot27B);
             pane.add(shoot28B);
             pane.add(shoot29B);
             pane.add(shoot30B);
             pane.add(shoot31B);
             pane.add(shoot32B);
             pane.add(shoot33B);
             pane.add(shoot34B);
             pane.add(shoot35B);
             pane.add(shoot36B);
             pane.add(shoot37B);
             pane.add(shoot38B);
             pane.add(shoot39B);
             pane.add(shoot40B);
             pane.add(shoot41B);
             pane.add(shoot42B);
             pane.add(shoot43B);
             pane.add(shoot44B);
             pane.add(shoot45B);
             pane.add(shoot46B);
             pane.add(shoot47B);
             pane.add(shoot48B);
             pane.add(shoot49B);
             pane.add(shoot50B);
             pane.add(shoot51B);
             pane.add(shoot52B);
             pane.add(shoot53B);
             pane.add(shoot54B);
             pane.add(shoot55B);
             pane.add(shoot56B);
             pane.add(shoot57B);
             pane.add(shoot58B);
             pane.add(shoot59B);
             pane.add(shoot60B);
             pane.add(shoot61B);
             pane.add(shoot62B);
             pane.add(shoot63B);
             pane.add(shoot64B);
             pane.add(shoot65B);
             pane.add(shoot66B);
             pane.add(shoot67B);
             pane.add(shoot68B);
             pane.add(shoot69B);
             pane.add(shoot70B);
             pane.add(shoot71B);
             pane.add(shoot72B);
             pane.add(shoot73B);
             pane.add(shoot74B);
             pane.add(shoot75B);
             pane.add(shoot76B);
             pane.add(shoot77B);
             pane.add(shoot78B);
             pane.add(shoot79B);
             pane.add(shoot80B);
             pane.add(shoot81B);
             pane.add(shoot82B);
             pane.add(shoot83B);
             pane.add(shoot84B);
             pane.add(shoot85B);
             pane.add(shoot86B);
             pane.add(shoot87B);
             pane.add(shoot88B);
             pane.add(shoot89B);
             pane.add(shoot90B);
             pane.add(shoot91B);
             pane.add(shoot92B);
             pane.add(shoot93B);
             pane.add(shoot94B);
             pane.add(shoot95B);
             pane.add(shoot96B);
             pane.add(shoot97B);
             pane.add(shoot98B);
             pane.add(shoot99B);
             pane.add(shoot100B);
     
    and
     
    if ( n == 2)
                { // beginning of if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
     
                } // end of if
                else if (n == 3)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
     
                } // end of else if
                else if (n == 4)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
     
                } // end of else if
                else if (n ==5)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
     
                } // end of else if
                else if (n == 6)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
     
                } // end of else if
     
                else if (n == 7)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
     
                } // end of else if
     
                else if (n == 8)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[0][7] = shoot8B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[1][7] = shoot18B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[2][7] = shoot28B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[3][7] = shoot38B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[4][7] = shoot48B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[5][7] = shoot58B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
                   arrayOfButtons[6][7] = shoot68B;
                   arrayOfButtons[7][0] = shoot71B;
                   arrayOfButtons[7][1] = shoot72B;
                   arrayOfButtons[7][2] = shoot73B;
                   arrayOfButtons[7][3] = shoot74B;
                   arrayOfButtons[7][4] = shoot75B;
                   arrayOfButtons[7][5] = shoot76B;
                   arrayOfButtons[7][6] = shoot77B;
                   arrayOfButtons[7][7] = shoot78B;
     
                } // end of else if
     
                else if (n == 9)
                { // beginning of else if
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[0][7] = shoot8B;
                   arrayOfButtons[0][8] = shoot9B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[1][7] = shoot18B;
                   arrayOfButtons[1][8] = shoot19B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[2][7] = shoot28B;
                   arrayOfButtons[2][8] = shoot29B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[3][7] = shoot38B;
                   arrayOfButtons[3][8] = shoot39B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[4][7] = shoot48B;
                   arrayOfButtons[4][8] = shoot49B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[5][7] = shoot58B;
                   arrayOfButtons[5][8] = shoot59B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
                   arrayOfButtons[6][7] = shoot68B;
                   arrayOfButtons[6][8] = shoot69B;
                   arrayOfButtons[7][0] = shoot71B;
                   arrayOfButtons[7][1] = shoot72B;
                   arrayOfButtons[7][2] = shoot73B;
                   arrayOfButtons[7][3] = shoot74B;
                   arrayOfButtons[7][4] = shoot75B;
                   arrayOfButtons[7][5] = shoot76B;
                   arrayOfButtons[7][6] = shoot77B;
                   arrayOfButtons[7][7] = shoot78B;
                   arrayOfButtons[7][8] = shoot79B;
                   arrayOfButtons[8][0] = shoot81B;
                   arrayOfButtons[8][1] = shoot82B;
                   arrayOfButtons[8][2] = shoot83B;
                   arrayOfButtons[8][3] = shoot84B;
                   arrayOfButtons[8][4] = shoot85B;
                   arrayOfButtons[8][5] = shoot86B;
                   arrayOfButtons[8][6] = shoot87B;
                   arrayOfButtons[8][7] = shoot88B;
                   arrayOfButtons[8][8] = shoot89B;
     
                } // end of else if
                else 
                { // beginning of else
                   arrayOfButtons[0][0] = shoot1B;
                   arrayOfButtons[0][1] = shoot2B;
                   arrayOfButtons[0][2] = shoot3B;
                   arrayOfButtons[0][3] = shoot4B;
                   arrayOfButtons[0][4] = shoot5B;
                   arrayOfButtons[0][5] = shoot6B;
                   arrayOfButtons[0][6] = shoot7B;
                   arrayOfButtons[0][7] = shoot8B;
                   arrayOfButtons[0][8] = shoot9B;
                   arrayOfButtons[0][9] = shoot10B;
                   arrayOfButtons[1][0] = shoot11B;
                   arrayOfButtons[1][1] = shoot12B;
                   arrayOfButtons[1][2] = shoot13B;
                   arrayOfButtons[1][3] = shoot14B;
                   arrayOfButtons[1][4] = shoot15B;
                   arrayOfButtons[1][5] = shoot16B;
                   arrayOfButtons[1][6] = shoot17B;
                   arrayOfButtons[1][7] = shoot18B;
                   arrayOfButtons[1][8] = shoot19B;
                   arrayOfButtons[1][9] = shoot20B;
                   arrayOfButtons[2][0] = shoot21B;
                   arrayOfButtons[2][1] = shoot22B;
                   arrayOfButtons[2][2] = shoot23B;
                   arrayOfButtons[2][3] = shoot24B;
                   arrayOfButtons[2][4] = shoot25B;
                   arrayOfButtons[2][5] = shoot26B;
                   arrayOfButtons[2][6] = shoot27B;
                   arrayOfButtons[2][7] = shoot28B;
                   arrayOfButtons[2][8] = shoot29B;
                   arrayOfButtons[2][9] = shoot30B;
                   arrayOfButtons[3][0] = shoot31B;
                   arrayOfButtons[3][1] = shoot32B;
                   arrayOfButtons[3][2] = shoot33B;
                   arrayOfButtons[3][3] = shoot34B;
                   arrayOfButtons[3][4] = shoot35B;
                   arrayOfButtons[3][5] = shoot36B;
                   arrayOfButtons[3][6] = shoot37B;
                   arrayOfButtons[3][7] = shoot38B;
                   arrayOfButtons[3][8] = shoot39B;
                   arrayOfButtons[3][9] = shoot40B;
                   arrayOfButtons[4][0] = shoot41B;
                   arrayOfButtons[4][1] = shoot42B;
                   arrayOfButtons[4][2] = shoot43B;
                   arrayOfButtons[4][3] = shoot44B;
                   arrayOfButtons[4][4] = shoot45B;
                   arrayOfButtons[4][5] = shoot46B;
                   arrayOfButtons[4][6] = shoot47B;
                   arrayOfButtons[4][7] = shoot48B;
                   arrayOfButtons[4][8] = shoot49B;
                   arrayOfButtons[4][9] = shoot50B;
                   arrayOfButtons[5][0] = shoot51B;
                   arrayOfButtons[5][1] = shoot52B;
                   arrayOfButtons[5][2] = shoot53B;
                   arrayOfButtons[5][3] = shoot54B;
                   arrayOfButtons[5][4] = shoot55B;
                   arrayOfButtons[5][5] = shoot56B;
                   arrayOfButtons[5][6] = shoot57B;
                   arrayOfButtons[5][7] = shoot58B;
                   arrayOfButtons[5][8] = shoot59B;
                   arrayOfButtons[5][9] = shoot60B;
                   arrayOfButtons[6][0] = shoot61B;
                   arrayOfButtons[6][1] = shoot62B;
                   arrayOfButtons[6][2] = shoot63B;
                   arrayOfButtons[6][3] = shoot64B;
                   arrayOfButtons[6][4] = shoot65B;
                   arrayOfButtons[6][5] = shoot66B;
                   arrayOfButtons[6][6] = shoot67B;
                   arrayOfButtons[6][7] = shoot68B;
                   arrayOfButtons[6][8] = shoot69B;
                   arrayOfButtons[6][9] = shoot70B;
                   arrayOfButtons[7][0] = shoot71B;
                   arrayOfButtons[7][1] = shoot72B;
                   arrayOfButtons[7][2] = shoot73B;
                   arrayOfButtons[7][3] = shoot74B;
                   arrayOfButtons[7][4] = shoot75B;
                   arrayOfButtons[7][5] = shoot76B;
                   arrayOfButtons[7][6] = shoot77B;
                   arrayOfButtons[7][7] = shoot78B;
                   arrayOfButtons[7][8] = shoot79B;
                   arrayOfButtons[7][9] = shoot80B;
                   arrayOfButtons[8][0] = shoot81B;
                   arrayOfButtons[8][1] = shoot82B;
                   arrayOfButtons[8][2] = shoot83B;
                   arrayOfButtons[8][3] = shoot84B;
                   arrayOfButtons[8][4] = shoot85B;
                   arrayOfButtons[8][5] = shoot86B;
                   arrayOfButtons[8][6] = shoot87B;
                   arrayOfButtons[8][7] = shoot88B;
                   arrayOfButtons[8][8] = shoot89B;
                   arrayOfButtons[8][9] = shoot90B;
                   arrayOfButtons[9][0] = shoot91B;
                   arrayOfButtons[9][1] = shoot92B;
                   arrayOfButtons[9][2] = shoot93B;
                   arrayOfButtons[9][3] = shoot94B;
                   arrayOfButtons[9][4] = shoot95B;
                   arrayOfButtons[9][5] = shoot96B;
                   arrayOfButtons[9][6] = shoot97B;
                   arrayOfButtons[9][7] = shoot98B;
                   arrayOfButtons[9][8] = shoot99B;
                   arrayOfButtons[9][9] = shoot100B;
     
     
                } // end of else
     
    and
     
     if ( n == 2)
             {  // beginning of if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(false);
                shoot4B.setVisible(false);
                shoot5B.setVisible(false);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(false);
                shoot14B.setVisible(false);
                shoot15B.setVisible(false);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(false);
                shoot22B.setVisible(false);
                shoot23B.setVisible(false);
                shoot24B.setVisible(false);
                shoot25B.setVisible(false);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(false);
                shoot32B.setVisible(false);
                shoot33B.setVisible(false);
                shoot34B.setVisible(false);
                shoot35B.setVisible(false);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(false);
                shoot42B.setVisible(false);
                shoot43B.setVisible(false);
                shoot44B.setVisible(false);
                shoot45B.setVisible(false);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of if
     
             else if (n == 3)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(false);
                shoot5B.setVisible(false);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(false);
                shoot15B.setVisible(false);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(false);
                shoot25B.setVisible(false);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(false);
                shoot32B.setVisible(false);
                shoot33B.setVisible(false);
                shoot34B.setVisible(false);
                shoot35B.setVisible(false);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(false);
                shoot42B.setVisible(false);
                shoot43B.setVisible(false);
                shoot44B.setVisible(false);
                shoot45B.setVisible(false);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 4)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(false);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(false);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(false);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(false);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(false);
                shoot42B.setVisible(false);
                shoot43B.setVisible(false);
                shoot44B.setVisible(false);
                shoot45B.setVisible(false);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 5)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(false);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(false);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(false);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(false);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(false);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(false);
                shoot52B.setVisible(false);
                shoot53B.setVisible(false);
                shoot54B.setVisible(false);
                shoot55B.setVisible(false);
                shoot56B.setVisible(false);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 6)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(false);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(false);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(false);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(false);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(false);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(false);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(false);
                shoot62B.setVisible(false);
                shoot63B.setVisible(false);
                shoot64B.setVisible(false);
                shoot65B.setVisible(false);
                shoot66B.setVisible(false);
                shoot67B.setVisible(false);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 7)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(false);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(false);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(false);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(false);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(false);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(false);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(false);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(false);
                shoot72B.setVisible(false);
                shoot73B.setVisible(false);
                shoot74B.setVisible(false);
                shoot75B.setVisible(false);
                shoot76B.setVisible(false);
                shoot77B.setVisible(false);
                shoot78B.setVisible(false);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 8)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(true);
                shoot9B.setVisible(false);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(true);
                shoot19B.setVisible(false);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(true);
                shoot29B.setVisible(false);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(true);
                shoot39B.setVisible(false);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(true);
                shoot49B.setVisible(false);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(true);
                shoot59B.setVisible(false);
                shoot60B.setVisible(false);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(true);
                shoot69B.setVisible(false);
                shoot70B.setVisible(false);
                shoot71B.setVisible(true);
                shoot72B.setVisible(true);
                shoot73B.setVisible(true);
                shoot74B.setVisible(true);
                shoot75B.setVisible(true);
                shoot76B.setVisible(true);
                shoot77B.setVisible(true);
                shoot78B.setVisible(true);
                shoot79B.setVisible(false);
                shoot80B.setVisible(false);
                shoot81B.setVisible(false);
                shoot82B.setVisible(false);
                shoot83B.setVisible(false);
                shoot84B.setVisible(false);
                shoot85B.setVisible(false);
                shoot86B.setVisible(false);
                shoot87B.setVisible(false);
                shoot88B.setVisible(false);
                shoot89B.setVisible(false);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else if (n == 9)
             { // beginning of else if
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(true);
                shoot9B.setVisible(true);
                shoot10B.setVisible(false);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(true);
                shoot19B.setVisible(true);
                shoot20B.setVisible(false);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(true);
                shoot29B.setVisible(true);
                shoot30B.setVisible(false);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(true);
                shoot39B.setVisible(true);
                shoot40B.setVisible(false);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(true);
                shoot49B.setVisible(true);
                shoot50B.setVisible(false);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(true);
                shoot59B.setVisible(true);
                shoot60B.setVisible(false);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(true);
                shoot69B.setVisible(true);
                shoot70B.setVisible(false);
                shoot71B.setVisible(true);
                shoot72B.setVisible(true);
                shoot73B.setVisible(true);
                shoot74B.setVisible(true);
                shoot75B.setVisible(true);
                shoot76B.setVisible(true);
                shoot77B.setVisible(true);
                shoot78B.setVisible(true);
                shoot79B.setVisible(true);
                shoot80B.setVisible(false);
                shoot81B.setVisible(true);
                shoot82B.setVisible(true);
                shoot83B.setVisible(true);
                shoot84B.setVisible(true);
                shoot85B.setVisible(true);
                shoot86B.setVisible(true);
                shoot87B.setVisible(true);
                shoot88B.setVisible(true);
                shoot89B.setVisible(true);
                shoot90B.setVisible(false);
                shoot91B.setVisible(false);
                shoot92B.setVisible(false);
                shoot93B.setVisible(false);
                shoot94B.setVisible(false);
                shoot95B.setVisible(false);
                shoot96B.setVisible(false);
                shoot97B.setVisible(false);
                shoot98B.setVisible(false);
                shoot99B.setVisible(false);
                shoot100B.setVisible(false);
             } // end of else if
     
             else
             { // beginning of else
                shoot1B.setVisible(true);
                shoot2B.setVisible(true);
                shoot3B.setVisible(true);
                shoot4B.setVisible(true);
                shoot5B.setVisible(true);
                shoot6B.setVisible(true);
                shoot7B.setVisible(true);
                shoot8B.setVisible(true);
                shoot9B.setVisible(true);
                shoot10B.setVisible(true);
                shoot11B.setVisible(true);
                shoot12B.setVisible(true);
                shoot13B.setVisible(true);
                shoot14B.setVisible(true);
                shoot15B.setVisible(true);
                shoot16B.setVisible(true);
                shoot17B.setVisible(true);
                shoot18B.setVisible(true);
                shoot19B.setVisible(true);
                shoot20B.setVisible(true);
                shoot21B.setVisible(true);
                shoot22B.setVisible(true);
                shoot23B.setVisible(true);
                shoot24B.setVisible(true);
                shoot25B.setVisible(true);
                shoot26B.setVisible(true);
                shoot27B.setVisible(true);
                shoot28B.setVisible(true);
                shoot29B.setVisible(true);
                shoot30B.setVisible(true);
                shoot31B.setVisible(true);
                shoot32B.setVisible(true);
                shoot33B.setVisible(true);
                shoot34B.setVisible(true);
                shoot35B.setVisible(true);
                shoot36B.setVisible(true);
                shoot37B.setVisible(true);
                shoot38B.setVisible(true);
                shoot39B.setVisible(true);
                shoot40B.setVisible(true);
                shoot41B.setVisible(true);
                shoot42B.setVisible(true);
                shoot43B.setVisible(true);
                shoot44B.setVisible(true);
                shoot45B.setVisible(true);
                shoot46B.setVisible(true);
                shoot47B.setVisible(true);
                shoot48B.setVisible(true);
                shoot49B.setVisible(true);
                shoot50B.setVisible(true);
                shoot51B.setVisible(true);
                shoot52B.setVisible(true);
                shoot53B.setVisible(true);
                shoot54B.setVisible(true);
                shoot55B.setVisible(true);
                shoot56B.setVisible(true);
                shoot57B.setVisible(true);
                shoot58B.setVisible(true);
                shoot59B.setVisible(true);
                shoot60B.setVisible(true);
                shoot61B.setVisible(true);
                shoot62B.setVisible(true);
                shoot63B.setVisible(true);
                shoot64B.setVisible(true);
                shoot65B.setVisible(true);
                shoot66B.setVisible(true);
                shoot67B.setVisible(true);
                shoot68B.setVisible(true);
                shoot69B.setVisible(true);
                shoot70B.setVisible(true);
                shoot71B.setVisible(true);
                shoot72B.setVisible(true);
                shoot73B.setVisible(true);
                shoot74B.setVisible(true);
                shoot75B.setVisible(true);
                shoot76B.setVisible(true);
                shoot77B.setVisible(true);
                shoot78B.setVisible(true);
                shoot79B.setVisible(true);
                shoot80B.setVisible(true);
                shoot81B.setVisible(true);
                shoot82B.setVisible(true);
                shoot83B.setVisible(true);
                shoot84B.setVisible(true);
                shoot85B.setVisible(true);
                shoot86B.setVisible(true);
                shoot87B.setVisible(true);
                shoot88B.setVisible(true);
                shoot89B.setVisible(true);
                shoot90B.setVisible(true);
                shoot91B.setVisible(true);
                shoot92B.setVisible(true);
                shoot93B.setVisible(true);
                shoot94B.setVisible(true);
                shoot95B.setVisible(true);
                shoot96B.setVisible(true);
                shoot97B.setVisible(true);
                shoot98B.setVisible(true);
                shoot99B.setVisible(true);
                shoot100B.setVisible(true);
             } // end of else

    It'll do all of what is replaced except get it in an n by n grid format.
    Last edited by helloworld922; June 4th, 2010 at 07:13 PM. Reason: please use [code] tags

  11. #9
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by Norm View Post
    Is that a logic question or a syntax problem? For the latter best way to find out is put it in a source and compile it.


    What is that?

    The variable buttons has to be declared somewhere that it can be seen by those that need to use it. Inside a method means that it will go away when the method exits.
    Inside a constructor for the class.

    If I can get an n by n grid, all those shoot1 - 100 B's and all of that unnecessary code can be deleted and greatly shorten the size of my program.

  12. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    Boy, you sure must like typing.

    You show several errors occurring at and after line 2222 in the program.
    It looks like you have a missing or misplaced { or }
    Hard to tell without seeing the code.

    What does the following mean:
    Also, won't format n by n with new code replacing very big amount shown earlier.

    for (int i = 0; i < arrayOfButtons.length; i++)
    {
    for ( int j = 0; j < arrayOfButtons[i].length; j++)
    {
    arrayOfButtons[i][j] = new JButton("0"); <<<<<<<<<<<<<<<<<<<<<< ALL BUTTONS WITH SAME LABEL???
    arrayOfButtons[i][j].addActionListener(this);
    arrayOfButtons[i][j].setVisible(true);
    pane.add(arrayOfButtons[i][j]);
    }
    }
    Please do NOT post such long useless pieces of code. Strip out most of it and replace with ... to show more of the same

  13. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (June 3rd, 2010)

  14. #11
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    /* The project makes an array of up to 100 buttons.  My
    	 if statements will keep asking user for a value between 2 and 10 till they do it.  Then I'm
    	 going to put the battleship in the array and then going to have actionEvent deal with if it's 
    	 not a hit and has a text of 0, I set them default to 0, then it changes the text of that button to an M.
    	 If they shoot there again one or more times, it changes it to an A.  If they actually hit the battleship, it changes the text to  an H, shows the number of shots, and then exits.  If they surrender, it asks them if they want to, and if they do, it shows the number of shots  and then exits.  If they quit, it asks them if they want to, and if they do, it just says a goodbye message and exits.  */
     
       import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
       import javax.swing.JFrame;
       import javax.swing.JDialog;
       import javax.swing.JPanel;
       import java.awt.Graphics;
       import javax.swing.ImageIcon;
       import java.util.*;
       import java.io.*;
       import java.awt.Component;
     
        public class BattleshipGUI extends JFrame 
        implements ActionListener
       { // beginning of class
        // label
          private JLabel shotsLabell;
     
       // area where text is displayed and user would normally enter text but I have made it so the user can't alter the shot count.
          private JTextField shotsTF;
     
          JFrame frame;
     
       // buttons
          private JButton surrenderB, quitB;
     
          private static final int WIDTH = 500;
          private static final int HEIGHT = 500;
     
     
           public BattleshipGUI()
          { // beginning of constructor
             setTitle("Battleship Game");
             Container pane = getContentPane();
             pane.setLayout(new GridLayout(11, 11));
     
                	// makes Label for shots
             shotsLabel = new JLabel("Shots: ",
                                      SwingConstants.RIGHT);
            // makes Text Field for shots and makes the text field non-editable
             shotsTF = new JTextField(7);      
             shotsTF.setEditable(false);
     
          			// makes the buttons and sets their value initially to 0 and makes the method actionPerformed
          			// a method of the class BattleshipGUI.  I don't need individual handlers.
     
             surrenderB = new JButton("Surrender");
             surrenderB.addActionListener(this);
     
             quitB = new JButton("Quit");
             quitB.addActionListener(this);
     
          // n is the size of the grid
             int n = 0;
             String gridSizeStr, outputStr;
          // while loop and boolean allow user to keep entering int values till n is between 2 and 10.  Also, it needs to have 
          // the array of buttons  in a square shape,  and also so I can place the battleship in the array and later use actionListeners to
          // change the text to either a M, an A, or a H.  Hence why all buttons in the array have the same label to begin with.
     
                  shotsTF.setText("0");
             boolean isValid = false;
     
             while (isValid == false)
             { // beginning of while
                try
                { // beginning of try
                   gridSizeStr = JOptionPane.showInputDialog("Enter the size of the grid:");
                   n = Integer.parseInt(gridSizeStr);
     
                   if (n < 2)
                      throw new MyTooSmallException();
     
                   if (n > 10)
                      throw new MyTooBigException();
     
                   isValid = true;
     
                } // end of try
     
                    catch ( MyTooSmallException mtse)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + " 2 and is no greater than 10. " +"\n " + mtse.toString() );
     
                   } // end of catch
     
                    catch ( MyTooBigException mtbe)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + "2 and is no greater than 10. " +"\n " + mtbe.toString() );
     
                   } // end of catch
     
     
                    catch (NumberFormatException nfeRef)          //Line 13
                   { // beginning of catch
                      JOptionPane.showMessageDialog(null,
                         "Enter an integer.  Exception "
                         + nfeRef.toString(),
                         "NumberFormatException",
                         JOptionPane.ERROR_MESSAGE);       //Line 14
                   } // end of catch
     
             } // end of while 
     
     
             if (n >=2 && n <= 10)
             { // beginning of if				
     
     
                JButton[][] arrayOfButtons = new JButton[n][n];
     
                for (int i = 0; i < arrayOfButtons.length; i++)
                {
                   for ( int j = 0; j < arrayOfButtons[i].length; j++)
    					{  // why does it need these brackets?
                      arrayOfButtons[i][j] = new JButton("0");
    						arrayOfButtons[i][j].addActionListener(this);
    						arrayOfButtons[i][j].setVisible(true);
    						pane.add(arrayOfButtons[i][j]);
     
    						} // why does it need these brackets?
                }
     
     
              pane.add(surrenderB);
    			 pane.add(quitB);
    			 pane.add(shotsLabel);
    			 pane.add(shotsTF);
     
    			  // the char array is where the actual 1 square battleship is going to be placed.
    			  // it is a n by n grid and the other array needs to be too to make them parallel.  
    			  // A value in the arrayOfButtons[i][j] should be the same as charArray[x][y].
     
     
                char [][] charArray = new char[n][n];
                for ( int x = 0; x < charArray.length; x++)
                {
                   for ( int y = 0; y < charArray[x].length; y++)
                      charArray[x][y] = '0';
     
                }
     
     
             } // end of if      
     
     
     
     
     
             quitB.setSize(80, 30);
             setSize(WIDTH, HEIGHT);
             setVisible(true);
             setDefaultCloseOperation(EXIT_ON_CLOSE);
     
     
          } // end of constructor
     
           public static void main(String[] args)
          { // beginning of main
             BattleshipGUI refVar = new BattleshipGUI();
     
          } // end of main
     
       	// this method handles the buttons.  
           public void actionPerformed(ActionEvent e)
          { // beginning of method
             String outputStr2, outputStr3, outputStr4, outputStr5, outputStr6;
             String outputStrM, outputStrA, outputStrAA;
             outputStrM = "Miss";
             outputStrA = "Already shot there";
             outputStrAA = "I told you that you already shot there";
     
             outputStr2 = "Are you sure you want to quit? ";
             outputStr3 = "You Quit.";
             outputStr4 = "Ok don't quit then." ;
             outputStr5 = "Thought not.";
             outputStr6 = "You surrendered.";
     
     
             int i, j, x,y;
             x = 0;
             i = 0;
             y = 0;
             j = 0;
     
             int shots =  Integer.parseInt(shotsTF.getText());
     
    			 JButton arrayOfButtons[][] = getStupidArray(arrayOfButtons, i, j) ;
              char charArray[][] = getStupidArray2(charArray, x, y);
     
              placeBattleship(charArray); 
     
             Integer tries;
             Integer tries2;
             Integer tries3;
             Integer tries4;
     
             tries = shots;
             tries2 = shots;
             tries3 = shots;
             tries4 = shots;
     
             if (e.getActionCommand().equals("Quit"))
             { // beginning of if
                Object[] options = {"Yes",
                        "Continue Playing"};
     
                int n = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Quit?",
                   "Quit",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options,     options[0]); 
             // creates Yes and Continue playing butons buttons.
             		// if Yee button is clicked, sends output "You quit." as heading and sends a message "Adiós!" and exits when 
             		// user clicks OK on dialog box
                if (n == JOptionPane.YES_OPTION) 
                { // beginning of if
                   JOptionPane.showMessageDialog(null,"Adiós!", outputStr3,  JOptionPane.PLAIN_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // Continue Playing, sends title "Ok don't quit then." and the message "Whatever." and takes the user back to the grid.
                else if (n == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null,"Whatever.",  outputStr4,  JOptionPane.PLAIN_MESSAGE);
                } // end of else if
     
             } // end of if
     
             else if (e.getActionCommand().equals("Surrender"))
             { // beginning of else if
                shots = shots + 1;
                Object[] options2 = {"Yes",
                        "No, I have not yet begun to fight!"};
                int p = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Surrender?",
                   "Surrender?",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options2,   options2[0]); 
             // creates Yes and No, I have not yet begun to fight! butons .
             		// if Yes button is clicked, sends output "You surrendered." as heading and sends a message "It took you [number of shots]
             		// shots!" and exits when user clicks OK on dialog box
                if (p == JOptionPane.YES_OPTION) 
                { // beginning of if
                // code for showing grid
                   arrayOfButtons[i][j].setText("B");
                   JOptionPane.showMessageDialog(null, "You took "  + shotsTF.getText() + " shots" , outputStr6, JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // "No button", sends output "Thought not." and the title "You didn't surrender." and takes the user back to the grid.
                else if (p == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null, outputStr5, "You didn't surrender." , JOptionPane.PLAIN_MESSAGE);
                } // end of else if
             } // end of else if
     
     
             else if (e.getActionCommand().equals("0"))
             { // beginning of else if
     
                if (  Fire(charArray, x, y) == 'H')
                { // beginning of if
                   String outputStr7;
                   arrayOfButtons[i][j].setText("H");  // changes text on button to H
                   shots = shots + 1;
                   tries = new Integer(shots);
                   shotsTF.setText(tries.toString());
     
                   outputStr7 = "You sank my battleship. " + "\n" + "You sank my battleship in" + shotsTF.getText() + "tries";
                   JOptionPane.showMessageDialog(null, outputStr7 , "You win!", +  JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                }// end of if
     
                else 
                { // beginning of else
                   JOptionPane.showMessageDialog(null, outputStrM , "You missed!", +  JOptionPane.INFORMATION_MESSAGE);
                   arrayOfButtons[i][j].setText("M"); // changes text on button to M
                   shots = shots + 1;
                   tries2 = new Integer(shots);
                   shotsTF.setText(tries2.toString());
     
                } // end of else
             } // end of else if 
                   // does this if text on button hit is M.
             else if (e.getActionCommand().equals("M"))
             { // beginning of else if
                shots = shots + 1;
                tries3 = new Integer(shots);
                shotsTF.setText(tries3.toString());
     
                JOptionPane.showMessageDialog(null, outputStrA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                arrayOfButtons[i][j].setText("A"); // changes text on button to A
             } // end of else if
                   // does this if text on button hit is A
             else if (e.getActionCommand().equals("A"))
             { // beginning of else if
                shots = shots + 1;
                tries4 = new Integer(shots);
                shotsTF.setText(tries4.toString());
     
                JOptionPane.showMessageDialog(null, outputStrAA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                arrayOfButtons[i][j].setText("A"); // changes text, sorta, on button to A
             } // end of else if
     
          } // end of method
     
          // the method placeBattleship, places the battleship by randomly choosing a
       // row and column coordinate and storing a 'B' there.  The 'B' is not displayed to 
       // the user unless the user hits the surrender button.  It takes the array as a parameter and 
       // should return nothing.  This method sets the location of the battleship.
     
    // do the following 4 methods need to be static or will that make it not work as the method actionPerformed is non-static?  
     
           private static void placeBattleship(char charArray[][])
          { // beginning of method placeBattleship
             int valueOne, valueTwo;
             char B;
             valueOne= (int) ( 1 + (Math.random() * charArray.length - 1 )); 
             valueTwo = (int) ( 1 + (Math.random() * charArray.length - 1));
             charArray[valueOne][valueTwo] = 'B';
     
          } //end of method placeBattleship
     
           public static char Fire(char charArray[][], int x, int y)
          { // beginning of method Fire
             char A;
             char M;
             char H;
     
                      if (charArray[x][y] == 'B')  // if battleship is hit return H and end game
             { // beginning of if statement
                charArray[x][y] = 'H';
     
     
                return ('H');
     
             } // end of if statement
     
             else if (charArray[x][y] == 'M')  // this is else if 
                                              // because it could also 
                                              // be just a miss.
     
             { // beginning of else if statement
     
                charArray[x][y] = 'A';
     
                return ('A');
             } // end of else if statement
     
             else if (charArray[x][y] == 'A') // makes sure it won't set an A to an M again.
             { // beginning of else if  
     
                charArray[x][y] = 'A';
                          return ('A');
             } // end of else if
             else
     
             { // beginning of else statement
                charArray[x][y] = 'M'; 
                return ('M');                                          
             } // end of else statement
          } // end of method fire
     
    		// this method should get it to return my array of buttons so I can call the method and set it to either
    		// arrayOfButtons[][] or just simply calling it may be enough.  The return type should be an array of 
    		// JButtons.  
     
           public static JButton [][] getStupidArray (JButton arrayOfButtons[][], int i, int j)
          {
           /*  for ( i = 0; i < arrayOfButtons.length; i++)
             {
                for ( j = 0; j < arrayOfButtons[i].length; j++)
                   arrayOfButtons[i][j].setText("0");
             }   is this part needed?  */ 
             return (arrayOfButtons[][]);
          }
     
    		 	// this method should get it to return my array of chars so I can call the method and set it to either
    		// charArray[][] or just simply calling it may be enough.  The return type should be a char array.
     
     
           public static char[][] getStupidArray2 (char charArray[][], int x, int y)
          {
    		/*
             for ( x = 0; x < charArray.length; x++)
             {
                for ( y = 0; y < charArray[x].length; y++)
                   charArray[x][y] = '0';
             } is this part needed?  */
             return  (charArray[][]);
          } 
     
       } // end of program
    Last edited by Json; June 3rd, 2010 at 09:12 AM. Reason: Please use code tags.

  15. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    Instead of using this large program to work out the techniques for defining objects and displaying them.
    Try writing a small special purpose program that only creates a few buttons (say 3x3) and displays them.
    When you get the technique, move it to the large program.

  16. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (June 3rd, 2010)

  17. #13
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    It works, but it won't be n by n for n=2 and n = 3.

    I did once get it to be n by n for n = 2 and 3 but it was wacked out for n =6 through n = 10.

    The only way to get it to work in a grid is to bring back all of that lengthy code.

    Will it throw it off if it's not in an n by n grid?

    Anyway, how do you set the return type to an array and get it to return that array?

    It's making me so mad that's why the method below got that name, because I've tried many things, all to no avail. However, my newest idea should in theory work, but it's not, though I have a feeling it's the syntax but don't know exactly what to fix.
    // this method should get it to return my array of buttons so I can call the method and set it to either
       	// arrayOfButtons[][] or just simply calling it may be enough.  The return type should be an array of 
       	// JButtons.  
     
           public static JButton [][] getStupidArray (JButton arrayOfButtons[][], int i, int j)
          {
           /*  for ( i = 0; i < arrayOfButtons.length; i++)
             {
                for ( j = 0; j < arrayOfButtons[i].length; j++)
                   arrayOfButtons[i][j].setText("0");
             }   is this part needed?  */ 
             return (arrayOfButtons[][]);
          }
    Last edited by helloworld922; June 4th, 2010 at 07:14 PM. Reason: please use [code] tags

  18. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    how do you set the return type to an array and get it to return that array
    Off the top of my head:
     public int[] returnArray() {
        int[] anArray = new int[5];
        return anArray;
      }
    return (arrayOfButtons[][]);
    This is the syntax to return an element of an array. However its missing the indexes.

    Why do you return an array from the method if that array is passed to the method as an arg?

  19. #15
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Smile Re: Battleship GUI Program

    Because you cannot both implement actionListener and add any parameters, except ActionEvent e, to actionPerformed or it won't be defining that abstract method.

  20. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    No idea what you are saying.
    If an object is defined outside of a method and you pass a reference to an array to the method. There is no reason to return a reference to the same array to the caller. The caller already has a reference to the array.

    Why call a method at all? You could code the loops shown in the getStupidArray () method in the code where the call to getStupidArray is made.

  21. #17
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    The call is made in the handler.

    How do you pass the array as a parameter to actionPerformed? It's abstract.

    It wants the arrays that were defined in the constructor but somehow are lost in the handler to be initialized or declared. But making a whole new array creates a NullPointerException.

    Here's the problem:

    Constructor for class
    {
     
    define arrayOne and make buttons, etc.
     
    define arrayTwo;
     
    } // end of constructor
     
    main method
    {
     
    }
     
    public void actionPerformed(ActionEvent e) // this is a method that was abstract and needs to be defined without adding any more parameters
    {
     
    code that needs to have arrays defined or else it won't work.
    if arrays are redeclared like they were first declared, it throws NullPointerException.
     
     
     
     
    } // end of handler
    method that takes arrayOne as parameter and returns it and it is called in handler;

    method that takes arrayTwo as parameter and returns it and it is called in handler;

    arrays have already been returned, I think.

    However, how do I declare/call them so they are defined and initialized, etc?

    I tried:
    	JButton arrayOfButtons[][] =  getStupidArray(arrayOfButtons, i, j) ;
     
    char charArray[][] = getStupidArray2(charArray, x, y);
    in the handler and even just
    getStupidArray(arrayOfButtons, i, j) ;
    getStupidArray2(charArray, x, y);
    The program is only supposed to create a 1 index battleship. Not several ones. That would require a lot more code and I need to get this part done first before I could attempt that.

    The battleship is being stored in charArray, which is supposed to be a parallel array of arrayOfButtons.

    However, as arrayOfButtons isn't n by n grid, I'm not 100 positive that it'll be parallel, but, unless I want to resurrect that old very long code, it won't be n by n always. Before it made 100 buttons and then only set those visible that made an n by n grid.

    I have no clue how to do that as I'd need to I'd need 100 buttons to start out with.

    Then I'd make only n by n visible, plus the other two and the shots label and the shots text field.
    Last edited by helloworld922; June 4th, 2010 at 07:15 PM. Reason: please use [code] tags

  22. #18
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by Norm View Post
    No idea what you are saying.
    If an object is defined outside of a method and you pass a reference to an array to the method. There is no reason to return a reference to the same array to the caller. The caller already has a reference to the array.

    Why call a method at all? You could code the loops shown in the getStupidArray () method in the code where the call to getStupidArray is made.
    Yes I could, but it's not even working correctly to define the arrays.

  23. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    it's not even working correctly to define the arrays
    What happens that is not correct? Compiler errors or execution errors?

    Your action listener method should be able to see class member variables.
    Define the two arrays outside of the constructor.
    Give them values inside the constructor where you are now defining them.
    Last edited by Norm; June 3rd, 2010 at 05:31 PM.

  24. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (June 3rd, 2010)

  25. #20
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by Norm View Post
    No idea what you are saying.
    If an object is defined outside of a method and you pass a reference to an array to the method. There is no reason to return a reference to the same array to the caller. The caller already has a reference to the array.

    Why call a method at all? You could code the loops shown in the getStupidArray () method in the code where the call to getStupidArray is made.

    import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
       import javax.swing.JFrame;
       import javax.swing.JDialog;
       import javax.swing.JPanel;
       import java.awt.Graphics;
       import javax.swing.ImageIcon;
       import java.util.*;
       import java.io.*;
       import java.awt.Component;
     
        public class BattleshipGUI extends JFrame 
     [B]   implements ActionListener[/B]  // because of this part, I cannot add more parameters to actionPerformed.  
       { // beginning of class
        // label
          private JLabel shotsLabel;
     
       // area where text is displayed and user would normally enter text but I have made it so the user can't alter the shot count.
          private JTextField shotsTF;
     
          JFrame frame;
     
       // buttons
          private JButton surrenderB, quitB;
     
          private static final int WIDTH = 500;
          private static final int HEIGHT = 500;
     
     
     
           public BattleshipGUI()
          { // beginning of constructor
             setTitle("Battleship Game");
             Container pane = getContentPane();
     
     
                	// makes Label for shots
             shotsLabel = new JLabel("Shots: ",
                                      SwingConstants.RIGHT);
            // makes Text Field for shots and makes the text field non-editable
             shotsTF = new JTextField(7);      
             shotsTF.setEditable(false);
     
          			// makes the buttons and sets their value initially to 0 and makes the method actionPerformed
          			// a method of the class BattleshipGUI.  I don't need individual handlers.
     
             surrenderB = new JButton("Surrender");
             surrenderB.addActionListener(this);
     
             quitB = new JButton("Quit");
             quitB.addActionListener(this);
     
          // n is the size of the grid
             int n = 0;
             String gridSizeStr, outputStr;
             boolean isInRange = false;
          // while loop and boolean allow user to keep entering int values till n is between 2 and 10.  Also, it needs to have 
          // the array of buttons  in a square shape,  and also so I can place the battleship in the array and later use actionListeners to
          // change the text to either a M, an A, or a H.  Hence why all buttons in the array have the same label to begin with.
     
             shotsTF.setText("0");
             boolean isValid = false;
     
             while (isValid == false)
             { // beginning of while
                try
                { // beginning of try
                   gridSizeStr = JOptionPane.showInputDialog("Enter the size of the grid:");
                   n = Integer.parseInt(gridSizeStr);
     
                   if (n < 2)
                      throw new MyTooSmallException();
     
                   if (n > 10)
                      throw new MyTooBigException();
     
                   isValid = true;
     
                } // end of try
     
                    catch ( MyTooSmallException mtse)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + " 2 and is no greater than 10. " +"\n " + mtse.toString() );
     
                   } // end of catch
     
                    catch ( MyTooBigException mtbe)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + "2 and is no greater than 10. " +"\n " + mtbe.toString() );
     
                   } // end of catch
     
     
                    catch (NumberFormatException nfeRef)          //Line 13
                   { // beginning of catch
                      JOptionPane.showMessageDialog(null,
                         "Enter an integer.  Exception "
                         + nfeRef.toString(),
                         "NumberFormatException",
                         JOptionPane.ERROR_MESSAGE);       //Line 14
                   } // end of catch
     
             } // end of while 
     
     
             if (n >=2 && n <= 10)
             { // beginning of if				
     
     
               [B] JButton[][] arrayOfButtons = new JButton[n][n];
               [/B]  arrayOfButtons is defined here.  
                for (int i = 0; i < arrayOfButtons.length; i++)
                {
                   for (  int j = 0; j < arrayOfButtons[i].length; j++)
                      arrayOfButtons[i][j] = new JButton("0");
                              }
     
    						for (int i = 0; i < arrayOfButtons.length; i++)
                {
                   for (  int j = 0; j < arrayOfButtons[i].length; j++)
                        arrayOfButtons[i][j].addActionListener(this);
                              }
     
    								 	for (int i = 0; i < arrayOfButtons.length; i++)
                {
                   for (  int j = 0; j < arrayOfButtons[i].length; j++)
    					pane.add(arrayOfButtons[i][j]);
                                                  }
     
     
     
             pane.setLayout(new GridLayout(n+1, n+1));
     
                pane.add(surrenderB);
                pane.add(quitB);
                pane.add(shotsLabel);
                pane.add(shotsTF);
     
               // the char array is where the actual 1 square battleship is going to be placed.
               // it is a n by n grid and the other array needs to be too to make them parallel.  
               // A value in the arrayOfButtons[i][j] should be the same as charArray[x][y].
     
               [B]
                char [][] charArray = new char[n][n];[/B]  // charArray is defined here.  
                for ( int x = 0; x < charArray.length; x++)
                {
                   for ( int y = 0; y < charArray[x].length; y++)
                      charArray[x][y] = '0';
     
                }
     
     
             } // end of if      
     
     
     
     
          // makes an n by n grid
     
     
             quitB.setSize(80, 30);
             setSize(WIDTH, HEIGHT);
             setVisible(true);
             setDefaultCloseOperation(EXIT_ON_CLOSE);
     
     
          } // end of constructor
     
           public static void main(String[] args)
          { // beginning of main
             BattleshipGUI refVar = new BattleshipGUI();
     
     
     
          } // end of main
     
       	// this method handles the buttons.  
           [B]public void actionPerformed(ActionEvent e)[/B]  This method defines an abstract method.  It's parameters can't be altered.  
          { // beginning of method
             String outputStr2, outputStr3, outputStr4, outputStr5, outputStr6;
             String outputStrM, outputStrA, outputStrAA;
             outputStrM = "Miss";
             outputStrA = "Already shot there";
             outputStrAA = "I told you that you already shot there";
     
             outputStr2 = "Are you sure you want to quit? ";
             outputStr3 = "You Quit.";
             outputStr4 = "Ok don't quit then." ;
             outputStr5 = "Thought not.";
             outputStr6 = "You surrendered.";
     
     
             int i, j, x,y;
             x = 0;
             i = 0;
             y = 0;
             j = 0;
     
             int shots =  Integer.parseInt(shotsTF.getText());
     
     
    			[B]JButton arrayOfButtons[][] =
             			  getStupidArray([I]arrayOfButtons[/I], i, j) ;[/B]  the array is supposed to be redefined here as it gets lost between the constructor and the method actionPerformed.  Could it be because the four methods below are all static and actionPerformed isn't?    It causes a compiler error.
     
     
    	     [B]   char charArray[][] = getStupidArray2([I]charArray[/I], x, y); [/B]  This redefinement won't work either.  It causes a compiler error.  
     
     
             placeBattleship([B]charArray[/B]);   // it can't find charArray's symbol, but as I have, clumsily, defined it above, the compiler appears to be happy there....for the moment.  
     
             Integer tries;
             Integer tries2;
             Integer tries3;
             Integer tries4;
     
             tries = shots;
             tries2 = shots;
             tries3 = shots;
             tries4 = shots;
     
             if (e.getActionCommand().equals("Quit"))
             { // beginning of if
                Object[] options = {"Yes",
                        "Continue Playing"};
     
                int n = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Quit?",
                   "Quit",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options,     options[0]); 
             // creates Yes and Continue playing butons buttons.
             		// if Yee button is clicked, sends output "You quit." as heading and sends a message "Adiós!" and exits when 
             		// user clicks OK on dialog box
                if (n == JOptionPane.YES_OPTION) 
                { // beginning of if
                   JOptionPane.showMessageDialog(null,"Adiós!", outputStr3,  JOptionPane.PLAIN_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // Continue Playing, sends title "Ok don't quit then." and the message "Whatever." and takes the user back to the grid.
                else if (n == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null,"Whatever.",  outputStr4,  JOptionPane.PLAIN_MESSAGE);
                } // end of else if
     
             } // end of if
     
             else if (e.getActionCommand().equals("Surrender"))
             { // beginning of else if
                shots = shots + 1;
                Object[] options2 = {"Yes",
                        "No, I have not yet begun to fight!"};
                int p = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Surrender?",
                   "Surrender?",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options2,   options2[0]); 
             // creates Yes and No, I have not yet begun to fight! butons .
             		// if Yes button is clicked, sends output "You surrendered." as heading and sends a message "It took you [number of shots]
             		// shots!" and exits when user clicks OK on dialog box
                if (p == JOptionPane.YES_OPTION) 
                { // beginning of if
                // code for showing grid
                   [B]arrayOfButtons[i][j][/B].setText("B");  // It normally can't find the symbol for this either.  
                   JOptionPane.showMessageDialog(null, "You took "  + shotsTF.getText() + " shots" , outputStr6, JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // "No button", sends output "Thought not." and the title "You didn't surrender." and takes the user back to the grid.
                else if (p == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null, outputStr5, "You didn't surrender." , JOptionPane.PLAIN_MESSAGE);
                } // end of else if
             } // end of else if
     
     
             else if (e.getActionCommand().equals("0"))  // this is so that initially, it'll handle whichever button has the text of 0, so I don't have to, though I couldn't as the number of buttons, and thus the number of handlers, would vary, use different handlers.  
             { // beginning of else if
     
                if (  Fire([B]charArray[/B], x, y) == 'H')  // It can't find the symbol for charArray here either.  
                { // beginning of if
                   String outputStr7;
                   [B]arrayOfButtons[i][j][/B].setText("H");  // changes text on button to H  
                  // can't find that symbol arrayOfButtons normally either.  
                   shots = shots + 1;
                   tries = new Integer(shots);
                   shotsTF.setText(tries.toString());
     
                   outputStr7 = "You sank my battleship. " + "\n" + "You sank my battleship in" + shotsTF.getText() + "tries";
                   JOptionPane.showMessageDialog(null, outputStr7 , "You win!", +  JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                }// end of if
     
                else 
                { // beginning of else
                   JOptionPane.showMessageDialog(null, outputStrM , "You missed!", +  JOptionPane.INFORMATION_MESSAGE);
                   [B]arrayOfButtons[i][j][/B].setText("M"); // changes text on button to M
                  // or this one 
                   shots = shots + 1;
                   tries2 = new Integer(shots);
                   shotsTF.setText(tries2.toString());
     
                } // end of else
             } // end of else if 
                   // does this if text on button hit is M.
             else if (e.getActionCommand().equals("M"))
             { // beginning of else if
                shots = shots + 1;
                tries3 = new Integer(shots);
                shotsTF.setText(tries3.toString());
     
                JOptionPane.showMessageDialog(null, outputStrA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                [B]arrayOfButtons[i][j][/B].setText("A"); // changes text on button to A
               // or this one
             } // end of else if
                   // does this if text on button hit is A
             else if (e.getActionCommand().equals("A"))
             { // beginning of else if
                shots = shots + 1;
                tries4 = new Integer(shots);
                shotsTF.setText(tries4.toString());
     
                JOptionPane.showMessageDialog(null, outputStrAA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                [B]arrayOfButtons[i][j][/B].setText("A"); // changes text, sorta, on button to A
           // or that one
             } // end of else if
     
          } // end of method
     
          // the method placeBattleship, places the battleship by randomly choosing a
       // row and column coordinate and storing a 'B' there.  The 'B' is not displayed to 
       // the user unless the user hits the surrender button.  It takes the array as a parameter and 
       // should return nothing.  This method sets the location of the battleship.
     
           private static void placeBattleship(char charArray[][])
          { // beginning of method placeBattleship
             int valueOne, valueTwo;
             char B;
             valueOne= (int) ( 1 + (Math.random() * charArray.length - 1 )); 
             valueTwo = (int) ( 1 + (Math.random() * charArray.length - 1));
             charArray[valueOne][valueTwo] = 'B';
     
          } //end of method placeBattleship
     
           public static char Fire(char charArray[][], int x, int y)
          { // beginning of method Fire
             char A;
             char M;
             char H;
     
             if (charArray[x][y] == 'B')  // if battleship is hit return H and end game
             { // beginning of if statement
                charArray[x][y] = 'H';
     
     
                return ('H');
     
             } // end of if statement
     
             else if (charArray[x][y] == 'M')  // this is else if 
                                              // because it could also 
                                              // be just a miss.
     
             { // beginning of else if statement
     
                charArray[x][y] = 'A';
     
                return ('A');
             } // end of else if statement
     
             else if (charArray[x][y] == 'A') // makes sure it won't set an A to an M again.
             { // beginning of else if  
     
                charArray[x][y] = 'A';
                return ('A');
             } // end of else if
             else
     
             { // beginning of else statement
                charArray[x][y] = 'M'; 
                return ('M');                                          
             } // end of else statement
          } // end of method fire
     
       	// this method should get it to return my array of buttons so I can call the method and set it to either
       	// arrayOfButtons[][] or just simply calling it may be enough.  The return type should be an array of 
       	// JButtons.  
     
           public static JButton [][] getStupidArray (JButton arrayOfButtons[][], int i, int j)
          {
     
             return (arrayOfButtons);
          }
     
       	 	// this method should get it to return my array of chars so I can call the method and set it to either
       	// charArray[][] or just simply calling it may be enough.  The return type should be a char array.
     
     
           public static char[][] getStupidArray2 (char [][] charArray, int x, int y)
          {
     
             for ( x = 0; x < charArray.length; x++)
             {
                for ( y = 0; y < charArray[x].length; y++)
                  System.out.println(charArray[x][y]);
             }
             return  (charArray);
          } 
     
       } // end of program

    Current 2 compiler errors:

    BattleshipGUI.java:219: variable arrayOfButtons might not have been initialized
    getStupidArray(arrayOfButtons, i, j) ;
    ^
    BattleshipGUI.java:222: variable charArray might not have been initialized
    char charArray[][] = getStupidArray2(charArray, x, y);

  26. #21
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by Norm View Post
    What happens that is not correct? Compiler errors or execution errors?

    Your action listener method should be able to see class member variables.
    Define the two arrays outside of the constructor.
    Give them values inside the constructor where you are now defining them.
    You're saying it is possible to define an array of buttons outside the constructor?

    Well, even so, I'd need to have two Container panes. One for the other non-array buttons and one for the array buttons.

    So I should define them in the actionListener method?

    Ok, that'll take care of charArray, but what about arrayOfButtons?

    And how can I give them values inside the constructor if they are defined outside it? Won't I run into the same problem as it'll say "Cannot find symbol"?
    Last edited by javapenguin; June 3rd, 2010 at 05:41 PM.

  27. #22
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
       import javax.swing.JFrame;
       import javax.swing.JDialog;
       import javax.swing.JPanel;
       import java.awt.Graphics;
       import javax.swing.ImageIcon;
       import java.util.*;
       import java.io.*;
       import java.awt.Component;
     
        public class BattleshipGUI extends JFrame 
        implements ActionListener
       { // beginning of class
        // label
          private JLabel shotsLabel, arraySize;
     
       // area where text is displayed and user would normally enter text but I have made it so the user can't alter the shot count.
          private JTextField shotsTF, arraySizeTF;
     
          JFrame frame;
     
       // buttons
          private JButton surrenderB, quitB;
     
          private static final int WIDTH = 500;
          private static final int HEIGHT = 500;
     
     
     
           public BattleshipGUI()
          { // beginning of constructor
             setTitle("Battleship Game");
             Container pane = getContentPane();
     
     
                	// makes Label for shots
             shotsLabel = new JLabel("Shots: ",
                                      SwingConstants.RIGHT);
    				 arraySize= new JLabel("Array Size ",
                                      SwingConstants.RIGHT);	
     
            // makes Text Field for shots and makes the text field non-editable
             shotsTF = new JTextField(7);      
             shotsTF.setEditable(false);
     
    			arraySizeTF = new JTextField(2);
    			arraySizeTF.setEditable(false);
     
          			// makes the buttons and sets their value initially to 0 and makes the method actionPerformed
          			// a method of the class BattleshipGUI.  I don't need individual handlers.
     
             surrenderB = new JButton("Surrender");
             surrenderB.addActionListener(this);
     
             quitB = new JButton("Quit");
             quitB.addActionListener(this);
     
          // n is the size of the grid
             int n = 0;
             String gridSizeStr, outputStr;
             boolean isInRange = false;
          // while loop and boolean allow user to keep entering int values till n is between 2 and 10.  Also, it needs to have 
          // the array of buttons  in a square shape,  and also so I can place the battleship in the array and later use actionListeners to
          // change the text to either a M, an A, or a H.  Hence why all buttons in the array have the same label to begin with.
     
             shotsTF.setText("0");
             boolean isValid = false;
     
             while (isValid == false)
             { // beginning of while
                try
                { // beginning of try
                   gridSizeStr = JOptionPane.showInputDialog("Enter the size of the grid:");
                   n = Integer.parseInt(gridSizeStr);
     
                   if (n < 2)
                      throw new MyTooSmallException();
     
                   if (n > 10)
                      throw new MyTooBigException();
     
                   isValid = true;
     
                } // end of try
     
                    catch ( MyTooSmallException mtse)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + " 2 and is no greater than 10. " +"\n " + mtse.toString() );
     
                   } // end of catch
     
                    catch ( MyTooBigException mtbe)
                   { // beginning of catch
     
                      JOptionPane.showMessageDialog(null, "Enter a value that is not less than" 
                         + "2 and is no greater than 10. " +"\n " + mtbe.toString() );
     
                   } // end of catch
     
     
                    catch (NumberFormatException nfeRef)          //Line 13
                   { // beginning of catch
                      JOptionPane.showMessageDialog(null,
                         "Enter an integer.  Exception "
                         + nfeRef.toString(),
                         "NumberFormatException",
                         JOptionPane.ERROR_MESSAGE);       //Line 14
                   } // end of catch
     
             } // end of while 
     
     
             if (n >=2 && n <= 10)
             { // beginning of if				
     
    				Integer Int;
     
    				Int = n;
     
    				arraySizeTF.setText(Int.toString());
     
    				         /*	 	char [][] charArray = new char[n][n];
                for (  int x = 0; x < charArray.length; x++)
                {
                   for (  int y = 0; y < charArray[x].length; y++)
                      charArray[x][y] = '0'; 
     
                } */
     
    			 JButton[][] arrayOfButtons = new JButton[n][n];
     
                for ( int i = 0; i < arrayOfButtons.length; i++)
                {
                   for (  int j = 0; j < arrayOfButtons[i].length; j++)
                      arrayOfButtons[i][j] = new JButton("0");
                              }
     
    						for (int i = 0; i < arrayOfButtons.length; i++)
                {
                   for (   int j = 0; j < arrayOfButtons[i].length; j++)
                        arrayOfButtons[i][j].addActionListener(this);
                              }
    								 Container pane2 = getContentPane();
     
    								 	for ( int i = 0; i < arrayOfButtons.length; i++)
                {
                   for (   int j = 0; j < arrayOfButtons[i].length; j++)
                       pane.add(arrayOfButtons[i][j]);
                              }
     
     
     
             pane.setLayout(new GridLayout(n+1, n+1));
     
     
                pane.add(surrenderB);
                pane.add(quitB);
                pane.add(shotsLabel);
                pane.add(shotsTF);
     
               // the char array is where the actual 1 square battleship is going to be placed.
               // it is a n by n grid and the other array needs to be too to make them parallel.  
               // A value in the arrayOfButtons[i][j] should be the same as charArray[x][y].
     
     
     
     
             } // end of if      
     
     
     
     
          // makes an n by n grid
     
     
                      setSize(WIDTH, HEIGHT);
             setVisible(true);
             setDefaultCloseOperation(EXIT_ON_CLOSE);
     
     
          } // end of constructor
     
           public static void main(String[] args)
          { // beginning of main
             BattleshipGUI refVar = new BattleshipGUI();
     
     
     
          } // end of main
     
       	// this method handles the buttons.  
           public void actionPerformed(ActionEvent e)
          { // beginning of method
             String outputStr2, outputStr3, outputStr4, outputStr5, outputStr6;
             String outputStrM, outputStrA, outputStrAA;
             outputStrM = "Miss";
             outputStrA = "Already shot there";
             outputStrAA = "I told you that you already shot there";
     
             outputStr2 = "Are you sure you want to quit? ";
             outputStr3 = "You Quit.";
             outputStr4 = "Ok don't quit then." ;
             outputStr5 = "Thought not.";
             outputStr6 = "You surrendered.";
     
     
             int i, j, x,y;
             x = 0;
             i = 0;
             y = 0;
             j = 0;
     
             int shots =  Integer.parseInt(shotsTF.getText());
     
    			int m = Integer.parseInt(arraySizeTF.getText());
     
    			char [][] charArray = new char[m][m];
                for (  x = 0; x < charArray.length; x++)
                {
                   for (  y = 0; y < charArray[x].length; y++)
                      charArray[x][y] = '0';
     
                }
     
    			 JButton[][] arrayOfButtons = new JButton[m][m];
     
                for ( i = 0; i < arrayOfButtons.length; i++)
                {
                   for (  j = 0; j < arrayOfButtons[i].length; j++)
                      arrayOfButtons[i][j] = new JButton("0");
                              }
     
    						for ( i = 0; i < arrayOfButtons.length; i++)
                {
                   for (   j = 0; j < arrayOfButtons[i].length; j++)
                        arrayOfButtons[i][j].addActionListener(this);
                              }
    								 Container pane2 = getContentPane();
     
    								 	for ( i = 0; i < arrayOfButtons.length; i++)
                {
                   for (   j = 0; j < arrayOfButtons[i].length; j++)
                       pane2.add(arrayOfButtons[i][j]);
                              }
     
    								 //	pane2.setLayout(new GridLayout((m+1), (m+1)));
     
     
     
     
     
             placeBattleship(charArray); 
     
             Integer tries;
             Integer tries2;
             Integer tries3;
             Integer tries4;
     
             tries = shots;
             tries2 = shots;
             tries3 = shots;
             tries4 = shots;
     
             if (e.getActionCommand().equals("Quit"))
             { // beginning of if
                Object[] options = {"Yes",
                        "Continue Playing"};
     
                int n = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Quit?",
                   "Quit",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options,     options[0]); 
             // creates Yes and Continue playing butons buttons.
             		// if Yee button is clicked, sends output "You quit." as heading and sends a message "Adiós!" and exits when 
             		// user clicks OK on dialog box
                if (n == JOptionPane.YES_OPTION) 
                { // beginning of if
                   JOptionPane.showMessageDialog(null,"Adiós!", outputStr3,  JOptionPane.PLAIN_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // Continue Playing, sends title "Ok don't quit then." and the message "Whatever." and takes the user back to the grid.
                else if (n == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null,"Whatever.",  outputStr4,  JOptionPane.PLAIN_MESSAGE);
                } // end of else if
     
             } // end of if
     
             else if (e.getActionCommand().equals("Surrender"))
             { // beginning of else if
                shots = shots + 1;
                Object[] options2 = {"Yes",
                        "No, I have not yet begun to fight!"};
                int p = JOptionPane.showOptionDialog(frame,
                   "Are you sure you want to Surrender?",
                   "Surrender?",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.QUESTION_MESSAGE,
                   null,        options2,   options2[0]); 
             // creates Yes and No, I have not yet begun to fight! butons .
             		// if Yes button is clicked, sends output "You surrendered." as heading and sends a message "It took you [number of shots]
             		// shots!" and exits when user clicks OK on dialog box
                if (p == JOptionPane.YES_OPTION) 
                { // beginning of if
                // code for showing grid
                   arrayOfButtons[i][j].setText("B");
                   JOptionPane.showMessageDialog(null, "You took "  + shotsTF.getText() + " shots" , outputStr6, JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                } // end of if
                // changes the string the standard dialog box for the No button but still uses its predefined return value.  If user clicks on 
                // "No button", sends output "Thought not." and the title "You didn't surrender." and takes the user back to the grid.
                else if (p == JOptionPane.NO_OPTION)
                { // beginning of else if
                   JOptionPane.showMessageDialog(null, outputStr5, "You didn't surrender." , JOptionPane.PLAIN_MESSAGE);
                } // end of else if
             } // end of else if
     
     
             else if (e.getActionCommand().equals("0"))
             { // beginning of else if
     
                if (  Fire(charArray, x, y) == 'H')
                { // beginning of if
                   String outputStr7;
                   arrayOfButtons[i][j].setText("H");  // changes text on button to H
                   shots = shots + 1;
                   tries = new Integer(shots);
                   shotsTF.setText(tries.toString());
     
                   outputStr7 = "You sank my battleship. " + "\n" + "You sank my battleship in" + shotsTF.getText() + "tries";
                   JOptionPane.showMessageDialog(null, outputStr7 , "You win!", +  JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);
                }// end of if
     
                else 
                { // beginning of else
                   JOptionPane.showMessageDialog(null, outputStrM , "You missed!", +  JOptionPane.INFORMATION_MESSAGE);
                   arrayOfButtons[i][j].setText("M"); // changes text on button to M
                   shots = shots + 1;
                   tries2 = new Integer(shots);
                   shotsTF.setText(tries2.toString());
     
                } // end of else
             } // end of else if 
                   // does this if text on button hit is M.
             else if (e.getActionCommand().equals("M"))
             { // beginning of else if
                shots = shots + 1;
                tries3 = new Integer(shots);
                shotsTF.setText(tries3.toString());
     
                JOptionPane.showMessageDialog(null, outputStrA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                arrayOfButtons[i][j].setText("A"); // changes text on button to A
             } // end of else if
                   // does this if text on button hit is A
             else if (e.getActionCommand().equals("A"))
             { // beginning of else if
                shots = shots + 1;
                tries4 = new Integer(shots);
                shotsTF.setText(tries4.toString());
     
                JOptionPane.showMessageDialog(null, outputStrAA , "Still a miss!", +  JOptionPane.INFORMATION_MESSAGE);
                arrayOfButtons[i][j].setText("A"); // changes text, sorta, on button to A
             } // end of else if
     
          } // end of method
     
          // the method placeBattleship, places the battleship by randomly choosing a
       // row and column coordinate and storing a 'B' there.  The 'B' is not displayed to 
       // the user unless the user hits the surrender button.  It takes the array as a parameter and 
       // should return nothing.  This method sets the location of the battleship.
     
           private static void placeBattleship(char charArray[][])
          { // beginning of method placeBattleship
             int valueOne, valueTwo;
             char B;
             valueOne= (int) ( 1 + (Math.random() * charArray.length - 1 )); 
             valueTwo = (int) ( 1 + (Math.random() * charArray.length - 1));
             charArray[valueOne][valueTwo] = 'B';
     
          } //end of method placeBattleship
     
           public static char Fire(char charArray[][], int x, int y)
          { // beginning of method Fire
             char A;
             char M;
             char H;
     
             if (charArray[x][y] == 'B')  // if battleship is hit return H and end game
             { // beginning of if statement
                charArray[x][y] = 'H';
     
     
                return ('H');
     
             } // end of if statement
     
             else if (charArray[x][y] == 'M')  // this is else if 
                                              // because it could also 
                                              // be just a miss.
     
             { // beginning of else if statement
     
                charArray[x][y] = 'A';
     
                return ('A');
             } // end of else if statement
     
             else if (charArray[x][y] == 'A') // makes sure it won't set an A to an M again.
             { // beginning of else if  
     
                charArray[x][y] = 'A';
                return ('A');
             } // end of else if
             else
     
             { // beginning of else statement
                charArray[x][y] = 'M'; 
                return ('M');                                          
             } // end of else statement
          } // end of method fire
     
     
       } // end of program
    No compiler errors.


    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3
    at BattleshipGUI.Fire(BattleshipGUI.java:407)
    at BattleshipGUI.actionPerformed(BattleshipGUI.java:3 40)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6263)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:602 8)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

    Last edited by helloworld922; June 4th, 2010 at 07:16 PM. Reason: please use [code] tags

  28. #23
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by Norm View Post
    What happens that is not correct? Compiler errors or execution errors?
    Well, compiler errors.

    What exactly do you mean by

    [QUOTE = Give them values inside the constructor where you are now defining them.[/QUOTE]

    Like redefine them? Tried that, gets those nasty exceptions.


  29. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Battleship GUI Program

    Please post your code in the [code ] tags to preserve indentations. Your unindented code is AWFUL!

    public class Testing {
      int[] anArray;  // Define a variable at the class level, outside the constructor
      // Constructor
      public Testing() {
        ...
         anArray = new int[5];  // Give the variable a value in the constructor
         ...
       } // end constructor
     
     
     
    } // end class


    How are the x,y set when calling the Fire() method? They appear to be left over from a for() loop.

    How do you determine which button was clicked? You'll need that to get the x,y.

    In general your code needs LOTS of println() statements to show how values are changing!!!
    Last edited by Norm; June 3rd, 2010 at 08:21 PM.

  30. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (June 3rd, 2010)

  31. #25
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Battleship GUI Program

    Quote Originally Posted by Norm View Post
    Please post your code in the [code ] tags to preserve indentations. Your unindented code is AWFUL!

    public class Testing {
      int[] anArray;  // Define a variable at the class level, outside the constructor
      // Constructor
      public Testing() {
        ...
         anArray = new int[5];  // Give the variable a value in the constructor
         ...
       } // end constructor
     
     
     
    } // end class









    How are the x,y set when calling the Fire() method? They appear to be left over from a for() loop.

    How do you determine which button was clicked? You'll need that to get the x,y.

    In general your code needs LOTS of println() statements to show how values are changing!!!
    Maybe so, but how do I get the buttons to be visible in the pane if it's mainly defined outside the constructor?

    Is it theoretically possible to define all of the buttons and labels and text fields outside the constructor and in the handler but before each button would be addressed with

    if (e.getActionCommand.equals("Button Text"))

    That would pretty much solve all the problems if it could.

    Why even bother having it in the constructor at all?

    Oh, define it at the top of the class.

    Last edited by javapenguin; June 4th, 2010 at 11:10 AM.

Page 1 of 4 123 ... LastLast