Skip to main content

Tic Tac Toe

1 reply [Last post]
word341
Offline
Joined: 2008-05-22
Points: 0

I need help, i cant determine whos the winner for this program, ive been working on this for weeks someone please help me.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TicTacToe implements ActionListener {

private JFrame window = new JFrame("Tic-Tac-Toe");
private JPanel inputPanel = new JPanel();
private JPanel boardPanel = new JPanel();
private JButton button3 = new JButton("3 by 3");
private JButton button4 = new JButton("4 by 4");
private JButton button5 = new JButton("5 by 5");
private JLabel label = new JLabel ("Click a button to choose game board size:");
private JButton buttons[][];
private int boardSize=0;
private int count = -1;
private String letter = "";
private boolean win = false;

public TicTacToe(){
//Create Window
window.setSize(500,500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Add Label and buttons to inputPanel
inputPanel.add(label);
inputPanel.add(button3);
inputPanel.add(button4);
inputPanel.add(button5);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
inputPanel.setSize(500,200);
window.add(inputPanel,"North");

//Make The Window Visible
window.setVisible(true);
}

public void actionPerformed(ActionEvent a) {
if(count==-1){
letter="-";
count=0;
}
else{
count++;

if(count % 2 == 0){
letter = "O";
} else {
letter = "X";
}
}

if (a.getSource() == button3) {
boardSize=3;
}
else if (a.getSource()== button4){
boardSize=4;
}
else if (a.getSource() == button5){
boardSize=5;
}
if ((a.getSource() == button3)||(a.getSource()==button4)||(a.getSource()==button5)){
button3.setEnabled(false);
button4.setEnabled(false);
button5.setEnabled(false);
buttons = new JButton[boardSize][boardSize];
for(int i=0; i

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

Please, use the Java forum for the Java question: http://forum.java.sun.com
Or just rewrite your application to JavaFX Script language.