Hi everyone
My code is still a bit messy as I;m pressed for time.
I have to write a simple game you play against the computer. I have my StartGUI class which instantiates the GUI and then I have a Game of Life class, which does not have a JFrame, but only contains code and logic.
The program compiles, but when I run it I get loads of EventQueue errors.
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6
at gamePackage.GameOfLife.<init>(GameOfLife.java:32)
at gamePackage.StartGUI.<init>(StartGUI.java:944)
at gamePackage.StartGUI$8.run(StartGUI.java:881)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.a
Here is my GameOfLife class. I left out irrelevent code to keep the post short:
package gamePackage;
/**
*
* @author MrSaVaGe
*/
public class GameOfLife {
/*DECLARATIONS OF VARIABLES
*
*/
//Array that stores the status of the board position. 0 = Empty, 1 = AI controlled, 2 = Player controlled.
int[][] blockStatus = new int[6][6];
int plyDepth;
boolean abPruning;
boolean playerTurn;
//DECLARATIONS OF FUNCTIONS
GameOfLife()
{
for (int i=0;i<6;i++)
for (int j=0;i<6;i++)
blockStatus[i][j] = 0;
blockStatus[0][0] = 1;
blockStatus[6][6] = 2;
plyDepth = 5;
abPruning = false;
playerTurn = true;
}
GameOfLife(int pd, boolean abp)
{
for (int i=0;i<6;i++)
for (int j=0;i<6;i++)
blockStatus[i][j] = 0;
blockStatus[0][0] = 1;
blockStatus[6][6] = 2;
plyDepth = pd;
abPruning = abp;
}
}
Here is my StartGUI class, sorry it contains alot of Netbeans generated code, but since the problem is specific to creating a new object of the class I don't think it is relevant to show it.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* StartGUI.java
*
* Created on 22 Mar 2014, 1:19:09 PM
*/
package gamePackage;
import java.awt.Color;
import java.awt.event.KeyEvent;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
/**
*
* @author MrSaVaGe
*/
public class StartGUI extends javax.swing.JFrame {
/** Creates new form StartGUI */
public StartGUI() {
initComponents();
gameBoardPanel.setVisible(false);
plyDepthField.setText("0");
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
playerOptionGroup = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jSeparator2 = new javax.swing.JSeparator();
jLabel3 = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
jLabel4 = new javax.swing.JLabel();
plyDepthField = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
pruningBox = new javax.swing.JCheckBox();
btnStart = new javax.swing.JButton();
jSeparator3 = new javax.swing.JSeparator();
gameBoardPanel = new javax.swing.JPanel();
gBlock1 = new javax.swing.JPanel();
gBlock2 = new javax.swing.JPanel();
gBlock3 = new javax.swing.JPanel();
gBlock4 = new javax.swing.JPanel();
gBlock5 = new javax.swing.JPanel();
gBlock6 = new javax.swing.JPanel();
gBlock7 = new javax.swing.JPanel();
gBlock8 = new javax.swing.JPanel();
gBlock9 = new javax.swing.JPanel();
gBlock10 = new javax.swing.JPanel();
gBlock11 = new javax.swing.JPanel();
gBlock12 = new javax.swing.JPanel();
gBlock13 = new javax.swing.JPanel();
gBlock14 = new javax.swing.JPanel();
gBlock15 = new javax.swing.JPanel();
gBlock16 = new javax.swing.JPanel();
gBlock17 = new javax.swing.JPanel();
gBlock18 = new javax.swing.JPanel();
gBlock19 = new javax.swing.JPanel();
gBlock20 = new javax.swing.JPanel();
gBlock21 = new javax.swing.JPanel();
gBlock22 = new javax.swing.JPanel();
gBlock23 = new javax.swing.JPanel();
gBlock24 = new javax.swing.JPanel();
gBlock25 = new javax.swing.JPanel();
gBlock26 = new javax.swing.JPanel();
gBlock27 = new javax.swing.JPanel();
gBlock28 = new javax.swing.JPanel();
gBlock29 = new javax.swing.JPanel();
gBlock30 = new javax.swing.JPanel();
gBlock31 = new javax.swing.JPanel();
gBlock32 = new javax.swing.JPanel();
gBlock33 = new javax.swing.JPanel();
gBlock34 = new javax.swing.JPanel();
gBlock35 = new javax.swing.JPanel();
gBlock36 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel1.setText("Game Of Life");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel2.setText("Settings:");
jLabel3.setText("Players:");
playerOptionGroup.add(jRadioButton1);
jRadioButton1.setText("Player vs. AI");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
playerOptionGroup.add(jRadioButton2);
jRadioButton2.setText("AI vs. AI");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
playerOptionGroup.add(jRadioButton3);
jRadioButton3.setText("Player vs. Player");
jLabel4.setText("AI:");
plyDepthField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
plyDepthFieldKeyTyped(evt);
}
});
jLabel5.setText("Ply depth:");
pruningBox.setText("Alpha-Beta pruning");
btnStart.setFont(new java.awt.Font("Tahoma", 1, 18));
btnStart.setText("START");
btnStart.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnStartMouseClicked(evt);
}
});
btnStart.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnStartActionPerformed(evt);
}
});
gameBoardPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
gameBoardPanel.setLayout(new java.awt.GridLayout(6, 6));
gBlock1.setBackground(new java.awt.Color(255, 0, 0));
gBlock1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
gBlock1.setPreferredSize(new java.awt.Dimension(40, 40));
gBlock1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
gBlock1MouseClicked(evt);
}
});
javax.swing.GroupLayout gBlock1Layout = new javax.swing.GroupLayout(gBlock1);
gBlock1.setLayout(gBlock1Layout);
gBlock1Layout.setHorizontalGroup(
gBlock1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock1Layout.setVerticalGroup(
gBlock1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock1);
gBlock2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
gBlock2.setPreferredSize(new java.awt.Dimension(40, 40));
gBlock2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
gBlock2MouseClicked(evt);
}
});
javax.swing.GroupLayout gBlock2Layout = new javax.swing.GroupLayout(gBlock2);
gBlock2.setLayout(gBlock2Layout);
gBlock2Layout.setHorizontalGroup(
gBlock2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock2Layout.setVerticalGroup(
gBlock2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock2);
gBlock3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock3Layout = new javax.swing.GroupLayout(gBlock3);
gBlock3.setLayout(gBlock3Layout);
gBlock3Layout.setHorizontalGroup(
gBlock3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock3Layout.setVerticalGroup(
gBlock3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock3);
gBlock4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock4Layout = new javax.swing.GroupLayout(gBlock4);
gBlock4.setLayout(gBlock4Layout);
gBlock4Layout.setHorizontalGroup(
gBlock4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock4Layout.setVerticalGroup(
gBlock4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock4);
gBlock5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock5Layout = new javax.swing.GroupLayout(gBlock5);
gBlock5.setLayout(gBlock5Layout);
gBlock5Layout.setHorizontalGroup(
gBlock5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock5Layout.setVerticalGroup(
gBlock5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock5);
gBlock6.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock6Layout = new javax.swing.GroupLayout(gBlock6);
gBlock6.setLayout(gBlock6Layout);
gBlock6Layout.setHorizontalGroup(
gBlock6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock6Layout.setVerticalGroup(
gBlock6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock6);
gBlock7.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock7Layout = new javax.swing.GroupLayout(gBlock7);
gBlock7.setLayout(gBlock7Layout);
gBlock7Layout.setHorizontalGroup(
gBlock7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock7Layout.setVerticalGroup(
gBlock7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock7);
gBlock8.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock8Layout = new javax.swing.GroupLayout(gBlock8);
gBlock8.setLayout(gBlock8Layout);
gBlock8Layout.setHorizontalGroup(
gBlock8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock8Layout.setVerticalGroup(
gBlock8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock8);
gBlock9.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock9Layout = new javax.swing.GroupLayout(gBlock9);
gBlock9.setLayout(gBlock9Layout);
gBlock9Layout.setHorizontalGroup(
gBlock9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock9Layout.setVerticalGroup(
gBlock9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock9);
gBlock10.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock10Layout = new javax.swing.GroupLayout(gBlock10);
gBlock10.setLayout(gBlock10Layout);
gBlock10Layout.setHorizontalGroup(
gBlock10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock10Layout.setVerticalGroup(
gBlock10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock10);
gBlock11.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock11Layout = new javax.swing.GroupLayout(gBlock11);
gBlock11.setLayout(gBlock11Layout);
gBlock11Layout.setHorizontalGroup(
gBlock11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock11Layout.setVerticalGroup(
gBlock11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock11);
gBlock12.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock12Layout = new javax.swing.GroupLayout(gBlock12);
gBlock12.setLayout(gBlock12Layout);
gBlock12Layout.setHorizontalGroup(
gBlock12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock12Layout.setVerticalGroup(
gBlock12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock12);
gBlock13.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock13Layout = new javax.swing.GroupLayout(gBlock13);
gBlock13.setLayout(gBlock13Layout);
gBlock13Layout.setHorizontalGroup(
gBlock13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock13Layout.setVerticalGroup(
gBlock13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock13);
gBlock14.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock14Layout = new javax.swing.GroupLayout(gBlock14);
gBlock14.setLayout(gBlock14Layout);
gBlock14Layout.setHorizontalGroup(
gBlock14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock14Layout.setVerticalGroup(
gBlock14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock14);
gBlock15.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock15Layout = new javax.swing.GroupLayout(gBlock15);
gBlock15.setLayout(gBlock15Layout);
gBlock15Layout.setHorizontalGroup(
gBlock15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock15Layout.setVerticalGroup(
gBlock15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock15);
gBlock16.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock16Layout = new javax.swing.GroupLayout(gBlock16);
gBlock16.setLayout(gBlock16Layout);
gBlock16Layout.setHorizontalGroup(
gBlock16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock16Layout.setVerticalGroup(
gBlock16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock16);
gBlock17.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock17Layout = new javax.swing.GroupLayout(gBlock17);
gBlock17.setLayout(gBlock17Layout);
gBlock17Layout.setHorizontalGroup(
gBlock17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock17Layout.setVerticalGroup(
gBlock17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock17);
gBlock18.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock18Layout = new javax.swing.GroupLayout(gBlock18);
gBlock18.setLayout(gBlock18Layout);
gBlock18Layout.setHorizontalGroup(
gBlock18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock18Layout.setVerticalGroup(
gBlock18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock18);
gBlock19.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock19Layout = new javax.swing.GroupLayout(gBlock19);
gBlock19.setLayout(gBlock19Layout);
gBlock19Layout.setHorizontalGroup(
gBlock19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock19Layout.setVerticalGroup(
gBlock19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock19);
gBlock20.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock20Layout = new javax.swing.GroupLayout(gBlock20);
gBlock20.setLayout(gBlock20Layout);
gBlock20Layout.setHorizontalGroup(
gBlock20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock20Layout.setVerticalGroup(
gBlock20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock20);
gBlock21.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock21Layout = new javax.swing.GroupLayout(gBlock21);
gBlock21.setLayout(gBlock21Layout);
gBlock21Layout.setHorizontalGroup(
gBlock21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock21Layout.setVerticalGroup(
gBlock21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock21);
gBlock22.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock22Layout = new javax.swing.GroupLayout(gBlock22);
gBlock22.setLayout(gBlock22Layout);
gBlock22Layout.setHorizontalGroup(
gBlock22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock22Layout.setVerticalGroup(
gBlock22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock22);
gBlock23.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock23Layout = new javax.swing.GroupLayout(gBlock23);
gBlock23.setLayout(gBlock23Layout);
gBlock23Layout.setHorizontalGroup(
gBlock23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock23Layout.setVerticalGroup(
gBlock23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock23);
gBlock24.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock24Layout = new javax.swing.GroupLayout(gBlock24);
gBlock24.setLayout(gBlock24Layout);
gBlock24Layout.setHorizontalGroup(
gBlock24Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock24Layout.setVerticalGroup(
gBlock24Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock24);
gBlock25.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock25Layout = new javax.swing.GroupLayout(gBlock25);
gBlock25.setLayout(gBlock25Layout);
gBlock25Layout.setHorizontalGroup(
gBlock25Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock25Layout.setVerticalGroup(
gBlock25Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock25);
gBlock26.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock26Layout = new javax.swing.GroupLayout(gBlock26);
gBlock26.setLayout(gBlock26Layout);
gBlock26Layout.setHorizontalGroup(
gBlock26Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock26Layout.setVerticalGroup(
gBlock26Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock26);
gBlock27.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock27Layout = new javax.swing.GroupLayout(gBlock27);
gBlock27.setLayout(gBlock27Layout);
gBlock27Layout.setHorizontalGroup(
gBlock27Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock27Layout.setVerticalGroup(
gBlock27Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock27);
gBlock28.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock28Layout = new javax.swing.GroupLayout(gBlock28);
gBlock28.setLayout(gBlock28Layout);
gBlock28Layout.setHorizontalGroup(
gBlock28Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock28Layout.setVerticalGroup(
gBlock28Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock28);
gBlock29.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock29Layout = new javax.swing.GroupLayout(gBlock29);
gBlock29.setLayout(gBlock29Layout);
gBlock29Layout.setHorizontalGroup(
gBlock29Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock29Layout.setVerticalGroup(
gBlock29Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock29);
gBlock30.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock30Layout = new javax.swing.GroupLayout(gBlock30);
gBlock30.setLayout(gBlock30Layout);
gBlock30Layout.setHorizontalGroup(
gBlock30Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock30Layout.setVerticalGroup(
gBlock30Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock30);
gBlock31.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock31Layout = new javax.swing.GroupLayout(gBlock31);
gBlock31.setLayout(gBlock31Layout);
gBlock31Layout.setHorizontalGroup(
gBlock31Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock31Layout.setVerticalGroup(
gBlock31Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock31);
gBlock32.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock32Layout = new javax.swing.GroupLayout(gBlock32);
gBlock32.setLayout(gBlock32Layout);
gBlock32Layout.setHorizontalGroup(
gBlock32Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock32Layout.setVerticalGroup(
gBlock32Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock32);
gBlock33.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock33Layout = new javax.swing.GroupLayout(gBlock33);
gBlock33.setLayout(gBlock33Layout);
gBlock33Layout.setHorizontalGroup(
gBlock33Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock33Layout.setVerticalGroup(
gBlock33Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock33);
gBlock34.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock34Layout = new javax.swing.GroupLayout(gBlock34);
gBlock34.setLayout(gBlock34Layout);
gBlock34Layout.setHorizontalGroup(
gBlock34Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock34Layout.setVerticalGroup(
gBlock34Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock34);
gBlock35.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock35Layout = new javax.swing.GroupLayout(gBlock35);
gBlock35.setLayout(gBlock35Layout);
gBlock35Layout.setHorizontalGroup(
gBlock35Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock35Layout.setVerticalGroup(
gBlock35Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock35);
gBlock36.setBackground(new java.awt.Color(0, 0, 255));
gBlock36.setBorder(javax.swing.BorderFactory.createEtchedBorder());
javax.swing.GroupLayout gBlock36Layout = new javax.swing.GroupLayout(gBlock36);
gBlock36.setLayout(gBlock36Layout);
gBlock36Layout.setHorizontalGroup(
gBlock36Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gBlock36Layout.setVerticalGroup(
gBlock36Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 58, Short.MAX_VALUE)
);
gameBoardPanel.add(gBlock36);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(134, 134, 134)
.addComponent(jLabel1)
.addContainerGap(150, Short.MAX_VALUE))
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(163, 163, 163)
.addComponent(jLabel2)
.addContainerGap(175, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton3)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton1)
.addComponent(jLabel3)
.addComponent(jRadioButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(plyDepthField, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(26, 26, 26))
.addComponent(pruningBox))))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(146, 146, 146)
.addComponent(btnStart, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(147, Short.MAX_VALUE))
.addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(gameBoardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(plyDepthField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pruningBox)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 1, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(19, 19, 19)
.addComponent(btnStart, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gameBoardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void plyDepthFieldKeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
char c = evt.getKeyChar();
if (!(Character.isDigit(c)) || (c==KeyEvent.VK_BACK_SPACE) || (c==KeyEvent.VK_DELETE))
{
evt.consume();
getToolkit().beep();
JOptionPane.showMessageDialog(null,"Enter ply depth numerically");
}
}
private void btnStartMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
// GameBoardGUI gbG new GameBoardGUI;
}
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {
//Displays game board
gameBoardPanel.setVisible(true);
//Gets ply depth and converts to integer
plydepth = Integer.parseInt(plyDepthField.getText().toString());
//Checks for pruning
if (pruningBox.isSelected())
abpruning = true;
else abpruning = false;
//Sends settings to Game of Life
//gol.settings(plydepth, abpruning);
}
private void gBlock1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (playerTurn == false)
{
getToolkit().beep();
JOptionPane.showMessageDialog(null, "Not your turn");
}
else if (playerTurn == true)
{
gBlock1.setBorder(BorderFactory.createEtchedBorder(Color.yellow, Color.yellow));
//gol.playerMove(0,1);
}
}
private void gBlock2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Windows".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(StartGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(StartGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(StartGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(StartGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new StartGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnStart;
private javax.swing.JPanel gBlock1;
private javax.swing.JPanel gBlock10;
private javax.swing.JPanel gBlock11;
private javax.swing.JPanel gBlock12;
private javax.swing.JPanel gBlock13;
private javax.swing.JPanel gBlock14;
private javax.swing.JPanel gBlock15;
private javax.swing.JPanel gBlock16;
private javax.swing.JPanel gBlock17;
private javax.swing.JPanel gBlock18;
private javax.swing.JPanel gBlock19;
private javax.swing.JPanel gBlock2;
private javax.swing.JPanel gBlock20;
private javax.swing.JPanel gBlock21;
private javax.swing.JPanel gBlock22;
private javax.swing.JPanel gBlock23;
private javax.swing.JPanel gBlock24;
private javax.swing.JPanel gBlock25;
private javax.swing.JPanel gBlock26;
private javax.swing.JPanel gBlock27;
private javax.swing.JPanel gBlock28;
private javax.swing.JPanel gBlock29;
private javax.swing.JPanel gBlock3;
private javax.swing.JPanel gBlock30;
private javax.swing.JPanel gBlock31;
private javax.swing.JPanel gBlock32;
private javax.swing.JPanel gBlock33;
private javax.swing.JPanel gBlock34;
private javax.swing.JPanel gBlock35;
private javax.swing.JPanel gBlock36;
private javax.swing.JPanel gBlock4;
private javax.swing.JPanel gBlock5;
private javax.swing.JPanel gBlock6;
private javax.swing.JPanel gBlock7;
private javax.swing.JPanel gBlock8;
private javax.swing.JPanel gBlock9;
private javax.swing.JPanel gameBoardPanel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.ButtonGroup playerOptionGroup;
private javax.swing.JTextField plyDepthField;
private javax.swing.JCheckBox pruningBox;
// End of variables declaration
//Local variables for game of life control
int plydepth;
boolean abpruning;
boolean playerTurn = false;
GameOfLife gol = new GameOfLife();
//boolean playerTurn = gol.playerTurn;
}
For your Convenience I put the call to my class at the bottom. PLease help!!