PDA

View Full Version : JAVA help



aanders5
02-02-2011, 05:39 PM
Ok, first off, this code is very messy and uncommented sooo if you know a decent amount on Java you should be able to navigate it for the most part.

I am making a connect4 game, and please don't refer me to the post below this one, as I can't follow it entirely. I am still very new to Java.

My issues right now revolve around three things.
1. Whenever I choose an odd number for the board size, it only displays an even amount of holes for the columns (if you test it you will see what I mean).
2. As you can see in my code, I am trying to somehow link up my JButtons to an actionlistener...basically be entitled buttons[0] to buttons[(board size)]. However, it only seems to loop and actually assign a listener to half of the buttons, not sure why it is doing that.
3. Once I do get the buttons working, how will I be able to get the JLabel images updated for a player's piece and at the same time only go down to the next available spot, rather than overlapping.

Those are my current issues right now and this code is ultra messy, so sorry about that.
(I've attached the images as well)

Also, I use Eclipse.
Code's in the spoiler



import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class GameEngine {

static JFrame frameMenu = new JFrame("Welcome to Connect 4!");

static JFrame frameBoard = new JFrame("Connect 4");

static JPanel panel_main = new JPanel();

static JPanel panel_main_top = new JPanel();

static JPanel panel_main_bottom = new JPanel();

static JPanel userSelection = new JPanel();

static JPanel boardSizeSelection = new JPanel();

static JPanel connectsSelection = new JPanel();

static JPanel usersBackground = new JPanel();

static JPanel connectsBackground = new JPanel();

static JPanel playersPresentPanel = new JPanel();

static JPanel boardBottom = new JPanel();

static JPanel boardPlane = new JPanel();

static JPanel boardButtons = new JPanel();

static JPanel boardMenu = new JPanel();

static JPanel bottomCombo = new JPanel();

static JPanel boardMiddle = new JPanel();

static JPanel buttonPlane = new JPanel();

static JPanel boardGame = new JPanel();

static JPanel buttonCombo = new JPanel();

static JPanel buttonCombo1 = new JPanel();

static JPanel buttonCombo2 = new JPanel();

static JLabel playersPresent = new JLabel();

static JLabel numberOfUsersMessage = new JLabel();

static JLabel boardSizeMessage = new JLabel();

static JLabel filler = new JLabel("");

static JLabel label;

static JPanel buttonRow = new JPanel();

static JLabel moveLocation = new JLabel();

static JLabel moveLocation1 = new JLabel();

static JLabel connectsMessage = new JLabel();

static JLabel onePlayerMessage = new JLabel();

static JLabel twoPlayerMessage = new JLabel();

static JLabel threePlayerMessage = new JLabel();

static JLabel fourPlayerMessage = new JLabel();

static JLabel fourWinsMessage = new JLabel();

static JLabel fiveWinsMessage = new JLabel();

static JLabel sixWinsMessage = new JLabel();

static JLabel sevenWinsMessage = new JLabel();

static JLabel eightWinsMessage = new JLabel();

static JLabel scoreBoardMessage = new JLabel();

static JLabel playerTurnMessage = new JLabel();

static JRadioButton twoUserSelection = new JRadioButton("", false);

static JRadioButton threeUserSelection = new JRadioButton("", false);

static JRadioButton fourUserSelection = new JRadioButton("", false);

static JRadioButton fourConnectsSelection = new JRadioButton("", false);

static JRadioButton fiveConnectsSelection = new JRadioButton("", false);

static JRadioButton sixConnectsSelection = new JRadioButton("", false);

static JRadioButton sevenConnectsSelection = new JRadioButton("", false);

static JRadioButton eightConnectsSelection = new JRadioButton("", false);

static Graphics2D ga = null;

int smallcounter = 0;

int counter = 0;

JButton[] buttons = new JButton[15];

static JTextField names = new JTextField(1);

static JTextField move = new JTextField(2);

static JTextField move1 = new JTextField(2);

static int player1_wins = 0;

static int player2_wins = 0;

static int player3_wins = 0;

static int player4_wins = 0;

static int turnTracker = 1;

static JButton buttonStart, buttonExit, buttonReset, buttonUndo;

static String Player_1 = "Player 1";

static String Player_2 = "Player 2";

static String Player_3 = "Player 3";

static String Player_4 = "Player 4";

static String boardType = "10x10";

static String boardRowsString = "10";

static String boardColsString = "10";

static int boardRows = 10;

static int boardCols = 10;

static JLabel[][] boardArray;

static int userStatus = 2;

static int connects = 4;

static boolean match = false;

static boolean winner = false;

static String[] boards = { "10x10", "11x11", "12x12", "13x13", "14x14",
"15x15" };

static JComboBox boardGroups = new JComboBox(boards);

static String board[][];

Dimension menuSize = new Dimension(500, 200);

Dimension backgroundBoard;

ImageIcon emptySpace = new ImageIcon(
"C:/Users/Austin/Desktop/Storage/Developer/Java_Items/shape/emptySpace.png");

ImageIcon player1Space = new ImageIcon(
"C:/Users/Austin/Desktop/Storage/Developer/Java_Items/shape/player1Space.png");

ImageIcon player2Space = new ImageIcon(
"C:/Users/Austin/Desktop/Storage/Developer/Java_Items/shape/player2Space.png");

ImageIcon player3Space = new ImageIcon(
"C:/Users/Austin/Desktop/Storage/Developer/Java_Items/shape/player3Space.png");

ImageIcon player4Space = new ImageIcon(
"C:/Users/Austin/Desktop/Storage/Developer/Java_Items/shape/player4Space.png");

static ImageIcon arrow = new ImageIcon(
"C:/Users/Austin/Desktop/Storage/Developer/Java_Items/shape/arrow.png");

static JButton button = new JButton(arrow);

MyMouseListener m = new MyMouseListener();

public static void main(String arg[]) {
GameEngine t = new GameEngine();
t.ProjectGUI();

}

public void ProjectGUI() {

WelcomeGUI();

}

class MyMouseListener extends MouseAdapter {

public MyMouseListener() {
super();
}

public void mouseClicked(MouseEvent evt) {
if (evt.getSource() == emptySpace) {
turnTracker++;
Messages();
}

}
}

private void WelcomeGUI() {

twoUserSelection.setSelected(true);
fourConnectsSelection.setSelected(true);

boardGroups.setSelectedIndex(0);
boardGroups.addActionListener(new e());
boardGroups.setBackground(Color.white);
userSelection.setLayout(new GridLayout(1, 1));

usersBackground.setLayout(new GridLayout(1, 1));

connectsBackground.setLayout(new GridLayout(1, 1));

twoPlayerMessage.setText("2");
twoUserSelection.addActionListener(new e());
userSelection.add(twoPlayerMessage);
userSelection.add(twoUserSelection);

threePlayerMessage.setText("3");
threeUserSelection.addActionListener(new e());
userSelection.add(threePlayerMessage);
userSelection.add(threeUserSelection);

fourPlayerMessage.setText("4");
fourUserSelection.addActionListener(new e());
userSelection.add(fourPlayerMessage);
userSelection.add(fourUserSelection);

fourWinsMessage.setText("4 ");
fourConnectsSelection.addActionListener(new e());
connectsSelection.add(fourWinsMessage);
connectsSelection.add(fourConnectsSelection);

fiveWinsMessage.setText("5 ");
fiveConnectsSelection.addActionListener(new e());
connectsSelection.add(fiveWinsMessage);
connectsSelection.add(fiveConnectsSelection);

sixWinsMessage.setText("6 ");
sixConnectsSelection.addActionListener(new e());
connectsSelection.add(sixWinsMessage);
connectsSelection.add(sixConnectsSelection);

sevenWinsMessage.setText("7 ");
sevenConnectsSelection.addActionListener(new e());
connectsSelection.add(sevenWinsMessage);
connectsSelection.add(sevenConnectsSelection);

eightWinsMessage.setText("8 ");
eightConnectsSelection.addActionListener(new e());
connectsSelection.add(eightWinsMessage);
connectsSelection.add(eightConnectsSelection);

boardSizeSelection.setBackground(Color.white);
boardSizeSelection.setLayout(new GridLayout(1, 1));
boardSizeSelection.add(boardGroups);

numberOfUsersMessage.setText("Mark the number of players: ");
boardSizeMessage.setText("Select a board size.");
connectsMessage.setText("Number of connects required for win: ");

usersBackground.add(numberOfUsersMessage);
connectsBackground.add(connectsMessage);

panel_main_top.setBackground(Color.white);
panel_main_top.setLayout(new GridLayout(3, 2));
panel_main_top.add(usersBackground);
panel_main_top.add(userSelection);
panel_main_top.add(boardSizeMessage);
panel_main_top.add(boardSizeSelection);
panel_main_top.add(connectsBackground);
panel_main_top.add(connectsSelection);

panel_main_bottom.setBackground(Color.white);
panel_main_bottom.setLayout(new GridLayout(1, 2));

buttonStart = new JButton("Start Game");
buttonStart.addActionListener(new e());
panel_main_bottom.add(buttonStart);

buttonExit = new JButton("Exit");
buttonExit.addActionListener(new e());
panel_main_bottom.add(buttonExit);

panel_main.setLayout(new GridLayout(2, 1));
panel_main.setBackground(Color.white);
panel_main.setBorder(BorderFactory.createLineBorde r(Color.black, 2));
panel_main.add(panel_main_top);
panel_main.add(panel_main_bottom);

frameMenu.setResizable(false);
frameMenu.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);
frameMenu.getContentPane().add(panel_main);
frameMenu.pack();
frameMenu.setSize(menuSize);
frameMenu.setVisible(true);

}

private void Messages() {

if (userStatus == 2) {
scoreBoardMessage.setText("Leader board: " + Player_1 + ": "
+ player1_wins + " | " + Player_2 + ": "
+ player2_wins);
}

if (userStatus == 3) {
scoreBoardMessage.setText("Leader board: " + Player_1 + ": "
+ player1_wins + " | " + Player_2 + ": "
+ player2_wins + " | " + Player_3 + ": "
+ player3_wins);
}
if (userStatus == 4) {
scoreBoardMessage.setText("Leader board: " + Player_1 + ": "
+ player1_wins + " | " + Player_2 + ": "
+ player2_wins + " | " + Player_3 + ": "
+ player3_wins + " | " + Player_4 + ": "
+ player4_wins);
}

if (turnTracker > userStatus) {
turnTracker = 1;
}
if (turnTracker == 1) {
playerTurnMessage.setText("It is " + Player_1 + "'s turn.");
} else {
if (turnTracker == 2) {
playerTurnMessage.setText("It is " + Player_2 + "'s turn.");
} else {
if (turnTracker == 3 && userStatus >= 3) {
playerTurnMessage.setText("It is " + Player_3 + "'s turn.");
} else {
if (turnTracker == 4 && userStatus == 4) {
playerTurnMessage.setText("It is " + Player_4
+ "'s turn.");
}
}

}
}

if (userStatus == 2) {
playersPresent.setText("Current Players: " + Player_1 + " | "
+ Player_2);
}

if (userStatus == 3) {
playersPresent.setText("Current Players: " + Player_1 + " | "
+ Player_2 + " | " + Player_3);
}
if (userStatus == 4) {
playersPresent.setText("Current Players: " + Player_1 + " | "
+ Player_2 + " | " + Player_3 + " | " + Player_4);
}
}

private void BoardGUI() {

boardMenu.setLayout(new GridLayout(2, 1));
boardMenu.setBackground(Color.white);
boardMenu.add(scoreBoardMessage);
boardMenu.add(playerTurnMessage);

buttonUndo = new JButton("Undo");
buttonUndo.addActionListener(new e());
boardButtons.add(buttonUndo);

buttonReset = new JButton("Reset");
buttonReset.addActionListener(new e());
boardButtons.add(buttonReset);

buttonExit = new JButton("Exit");
buttonExit.addActionListener(new e());
boardButtons.add(buttonExit);

boardMiddle.setLayout(new BorderLayout());
boardMiddle.add(buttonRow, BorderLayout.NORTH);
boardMiddle.add(boardPlane, BorderLayout.CENTER);

boardGame.setLayout(new BorderLayout());

boardGame.add(boardMenu, BorderLayout.NORTH);
boardGame.add(boardMiddle, BorderLayout.CENTER);
boardGame.add(boardButtons, BorderLayout.SOUTH);

boardGame.setBackground(Color.white);
boardGame.setBorder(BorderFactory.createLineBorder (Color.black, 2));

}

public void buttonBuilder() {
int h = 0;
buttonRow.setLayout(new GridLayout(1, 15));
for (h = 0; h < (boardRows/2); h++) {

buttons[h] = new JButton(arrow);
buttons[h].addActionListener(new e());
buttons[h].setHorizontalAlignment(JLabel.CENTER);
buttonRow.add(buttons[h]);
System.out.println("hcount: " + h);

if (h == boardRows - 1) {
break;
}
}
}

public class e implements ActionListener {

public void actionPerformed(ActionEvent e) {
Object source = e.getSource();

if (source == buttonStart) {
boardSetup();
getNames();
startGame();

}

if (source == twoUserSelection) {
threeUserSelection.setSelected(false);
fourUserSelection.setSelected(false);
userStatus = 2;
}

if (source == threeUserSelection) {
twoUserSelection.setSelected(false);
fourUserSelection.setSelected(false);
userStatus = 3;
}

if (source == fourUserSelection) {
twoUserSelection.setSelected(false);
threeUserSelection.setSelected(false);
userStatus = 4;
}

if (source == fourConnectsSelection) {
fiveConnectsSelection.setSelected(false);
sixConnectsSelection.setSelected(false);
sevenConnectsSelection.setSelected(false);
eightConnectsSelection.setSelected(false);
connects = 4;
}

if (source == fiveConnectsSelection) {
fourConnectsSelection.setSelected(false);
sixConnectsSelection.setSelected(false);
sevenConnectsSelection.setSelected(false);
eightConnectsSelection.setSelected(false);
connects = 5;
}

if (source == sixConnectsSelection) {
fourConnectsSelection.setSelected(false);
fiveConnectsSelection.setSelected(false);
sevenConnectsSelection.setSelected(false);
eightConnectsSelection.setSelected(false);
connects = 6;
}

if (source == sevenConnectsSelection) {
fourConnectsSelection.setSelected(false);
fiveConnectsSelection.setSelected(false);
sixConnectsSelection.setSelected(false);
eightConnectsSelection.setSelected(false);
connects = 7;
}

if (source == eightConnectsSelection) {
fourConnectsSelection.setSelected(false);
fiveConnectsSelection.setSelected(false);
sixConnectsSelection.setSelected(false);
sevenConnectsSelection.setSelected(false);
connects = 8;
}

if (source == boardGroups) {

}

if (source == buttons[1]) {
System.out.println("1");
Update();
if (userStatus == 1) {

}
}

if (source == buttons[2]) {
System.out.println("2");
Update();
}

if (source == buttons[3]) {
System.out.println("3");
Update();
}

if (source == buttons[4]) {
System.out.println("4");
Update();
}

if (source == buttons[5]) {
System.out.println("5");
Update();
}

if (source == buttons[6]) {
System.out.println("6");
Update();
}

if (source == buttons[7]) {
System.out.println("7");
Update();
}

if (source == buttons[8]) {
System.out.println("8");
Update();
}

if (source == buttons[9]) {
System.out.println("9");
Update();
}

if (source == buttons[10]) {
System.out.println("10");
Update();
}

if (source == buttons[11]) {
System.out.println("11");
Update();
}

if (source == buttons[12]) {
System.out.println("12");
Update();
}

if (source == buttons[13]) {
System.out.println("13");
Update();
}

if (source == buttons[14]) {
System.out.println("14");
Update();
}

if (source == buttonExit) {
System.exit(1);
}

if (source == buttonUndo) {

turnTracker--;
smallcounter--;
if (turnTracker <= 0 && counter > 0) {
turnTracker = 4;
counter--;
} else {
playerTurnMessage.setText("You cannot undo any further.");
playerTurnMessage.setForeground(Color.red);

}
Messages();

}
}

private void Update() {
playerTurnMessage.setForeground(Color.black);
smallcounter++;
if (smallcounter == 4) {
smallcounter = 0;
counter++;
}
turnTracker++;
if (turnTracker == 5) {
turnTracker = 1;
}
Messages();
}

private void getNames() {
if (userStatus == 2) {
Player_1 = JOptionPane.showInputDialog(null,
"Please enter player 1's name");

Player_2 = JOptionPane.showInputDialog(null,
"Please enter player 2's name");

}
if (userStatus == 3) {
Player_1 = JOptionPane.showInputDialog(null,
"Please enter player 1's name");

Player_2 = JOptionPane.showInputDialog(null,
"Please enter player 2's name");
Player_3 = JOptionPane.showInputDialog(null,
"Please enter player 3's name");
}
if (userStatus == 4) {
Player_1 = JOptionPane.showInputDialog(null,
"Please enter player 1's name");
Player_2 = JOptionPane.showInputDialog(null,
"Please enter player 2's name");
Player_3 = JOptionPane.showInputDialog(null,
"Please enter player 3's name");
Player_4 = JOptionPane.showInputDialog(null,
"Please enter player 4's name");
}

}

private void startGame() {
boardSetup();
BoardGUI();
}

private void packageBoard() {
frameBoard.setResizable(false);
frameBoard.setDefaultCloseOperation(JFrame.EXIT_ON _CLOSE);
frameBoard.getContentPane().add(boardGame);
frameBoard.pack();
frameBoard.setSize(backgroundBoard);
frameMenu.setVisible(false);
frameBoard.setVisible(true);

}

private void boardSetup() {
boardType = boardGroups.getSelectedItem().toString();
boardRowsString = boardType.substring(0, 2);
boardColsString = boardRowsString;
boardRows = Integer.parseInt(boardRowsString);
boardCols = Integer.parseInt(boardColsString);
backgroundBoard = new Dimension((boardRows * 45), (boardCols * 40));

panelMaker();
Messages();
packageBoard();
buttonBuilder();

}

public void horizontalCheck() {
String playerMark = null;
int size = boardRows;
for (int row = 0; row < size; row++) {
for (int col = 0; col < size - connects; col++) {
match = true;
for (int i = 0; i < connects; i++) {

if (board[row][col + i] != playerMark) {
match = false;

}
}
if (match = true) {
winner = true;
}

}
}

}

public void verticallCheck() {
String playerMark = null;
int size = boardRows;
for (int col = 0; col < size; col++) {
for (int row = 0; row < size - connects; row++) {
match = true;
for (int i = 0; i < connects; i++) {

if (board[row + i][col] != playerMark) {
match = false;

}
}
if (match = true) {
winner = true;
}

}
}
}

public void diagonal1Check() {

}

public void diagonal2Check() {

}

private void panelMaker() {
JLabel[][] boardnew = new JLabel[boardRows][boardCols];
boardPlane.setLayout(new GridLayout(boardRows, (boardCols / 2)));
boardPlane
.setBorder(BorderFactory.createLineBorder(Color.bl ack, 2));
boardPlane.setBackground(Color.yellow);
int i = 0;
int j = 0;
int k = 0;

for (i = 0; i < boardRows; i++) {

for (j = 0; j < (boardCols / 2); j++) {

boardnew[i][j] = new JLabel(emptySpace);
boardnew[i][j].setHorizontalAlignment(JLabel.CENTER);
boardPlane.add(boardnew[i][j]);

}
}

}

}

}





I attached the player piece images, however the arrow image didn't want to upload so I hosted that one offshore, here: http://i421.photobucket.com/albums/pp296/rskom/arrow.png


Thank you guys so much!
-Austin

SonniE
02-02-2011, 10:46 PM
Don't really have time to help but heres my version i made my 1st year with java.


/**
* ConnectFour [Version 1.50]
* @author Brian SonniE
* @Source: FluidCoding.com
* @version 1.50 2009/9/12
*/

import javax.swing.*;
import java.awt.*;
import java.io.*;
import javax.imageio.*;
import java.awt.event.*;
import java.net.*;
import java.awt.image.*;
import javax.swing.ImageIcon;

public class ConnectFour extends JFrame{
private JPanel mainPane;
private JButton[] slots;
private JButton[] selector;
// Set Images
ImageIcon emptySpace = new ImageIcon(ConnectFour.class.getResource("images/whitecon.png"));
ImageIcon blackSpace = new ImageIcon(ConnectFour.class.getResource("images/blackcon.png"));
ImageIcon redSpace = new ImageIcon(ConnectFour.class.getResource("images/redcon.png"));
ImageIcon selectIcon = new ImageIcon(ConnectFour.class.getResource("images/selectcon.png"));
int[] board;
int turn = 1;
int tieCounter = 0;
boolean gameRunning = true;

/**
*Constructor
*/
public ConnectFour()
{
setTitle("SonniE's ConnectFour");
setVisible(true);
setSize(600,550);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildMainPane();
}
/**
* Setup Gui
*/
public void buildMainPane()
{
mainPane = new JPanel(new GridLayout(7,6));
mainPane.setBackground(Color.black);

board = new int[42];
slots = new JButton[42];
selector = new JButton[7];

// Init Buttons/Board
for(int ct=0; ct< 7; ct++)
{
selector[ct] = new JButton(selectIcon);
selector[ct].addActionListener(new SelectListener());
mainPane.add(selector[ct]);
}
for(int ct=0; ct<42; ct++)
{
board[ct] = 0;
slots[ct] = new JButton(emptySpace);
mainPane.add(slots[ct]);
}

add(mainPane);
}

private class SelectListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
boolean validMove = true;
int activeColumn = 0;
int activePiece = 0;
ImageIcon activeIcon = redSpace;
if(turn == 1)
{
activeIcon = blackSpace;
}
Object obj = e.getSource();
// Get Column
for(int i=0; i<7; i++)
{
if(obj == selector[i])
activeColumn = i;
}
// Get Row
activePiece = 5*7+activeColumn;
for(int i = 0; i<6; i++)
{
if(board[activePiece] == 0)
{
board[activePiece] = turn;
break;
}
else
{
activePiece-=7;
}
}
// Check if Valid
if(activePiece<0)
validMove=false;
else{

slots[activePiece].setIcon(activeIcon);

// Check 4 Win

// Check Horizontal Win
for(int ct=0; ct<39; ct++)
{
if(ct%7<5)
{
if(board[ct] != 0 && board[ct] == board[ct+1] && board[ct] == board[ct+2] && board[ct] == board[ct+3])
{
gameRunning = false;
}
}
}

// Check Vertical Win

for(int ct=0; ct<22; ct++)
{
if(board[ct] != 0 && board[ct] == board[ct+7] && board[ct] == board[ct+14] && board[ct] == board[ct+21])
{
gameRunning = false;
}
}

// Check Diagnol Win
// L to R
for (int ct = 0; ct < 18; ct++)
{
if (ct % 7 < 4)
{
if(board[ct] != 0 && board[ct] == board[ct+8] && board[ct] == board[ct+16] && board[ct] == board[ct+24])
{
gameRunning = false;
}
}
}

for(int ct=0; ct<24; ct++)
{
if(ct % 7 > 2)
{
if(board[ct] != 0 && board[ct] == board[ct+6] && board[ct] == board[ct+12] && board[ct] == board[ct+18])
{
gameRunning = false;

}
}
}


// Display Winner Message
if(!gameRunning)
{
if(turn==1)
JOptionPane.showMessageDialog(null, "Player 1 Wins!!!");
else
JOptionPane.showMessageDialog(null, "Player 2 Wins!!!");

for(int i = 0; i<7; i++)
selector[i].setEnabled(false);
}

tieCounter++;
if(tieCounter==42)
{
JOptionPane.showMessageDialog(null, "Tie You Both Lose!!!");
gameRunning = false;
for(int i = 0; i<7; i++)
selector[i].setEnabled(false);
}
// Update Player Turn
if(turn==1)
turn = 2;
else
turn = 1;
if(!gameRunning)
{
int n = JOptionPane.showConfirmDialog(null,
"Would You Like a Rematch",
"New Game?",
JOptionPane.YES_NO_OPTION);

if(n == 0)
restartGame();

else
System.exit(0);
}
}
}
}
public void restartGame()
{
for(int i = 0; i<42; i++)
{
slots[i].setIcon(emptySpace);
board[i] = 0;
turn = 1;
tieCounter = 0;
gameRunning = true;
}
for(int i =0; i<7; i++)
selector[i].setEnabled(true);
}

public static void main(String[] args) {
ConnectFour window = new ConnectFour();
}
}

icevirus
02-05-2011, 08:14 PM
Bravo.

Ay you know about the new coder Ruffian? well he isnt new but he makes good codes now for SF