I think I almost have a TicTacToe game working, in the actionPerformed method I included a random number so the computer would make a move on the grid right after a user make a move. Well, this is where I am stucked! I make a move, then the PC makes a move, so far so good but after I make a second move the applet does not make another move.
I double checked the loop and cannot see anything wrong, the way a read it, It should make a move after I do each time.
I am clearly missing something and I just dont know what.
If anyone steps in THXs in advance.
CODE
import java.util.*;
import java.util.Random;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JTicTacToe extends JApplet implements ActionListener
{
JLabel someText = new JLabel(" Enter the number of expected guest for the event: ");
JTextField firstNum = new JTextField(15);
JLabel test_two = new JLabel("");
Container test = getContentPane();
Random rand = new java.util.Random();
String letter4User = "X";
String letterForPC = "O";
String[] dummyInput = {" ", " ", " ", " ", " ", " ", " ", " ", " "};
int [] verify = { 0, 1, 2, 3, 4, 5, 6, 7, 8};
JButton[] TicTac = new JButton[dummyInput.length];
int random = ((int) (Math.random() * 100) % 9 + 1);
Font convertion = new Font ("Bookman Old Style", Font.ITALIC, 13);
public void init()
{
test.setLayout(new FlowLayout());
firstNum.addActionListener(this);
for(int y = 0; y < dummyInput.length; y++)
{
TicTac[y] = new JButton(dummyInput[y]);
test.add(TicTac[y]);
TicTac[y].addActionListener(this);
}
}
public void actionPerformed(ActionEvent r)
{
Object source = r.getSource();
for(int b = 0; b < TicTac.length; b++)
if(source == TicTac[b] )
{
TicTac[b].setText(letter4User);
TicTac[random].setText(letterForPC);
}
}
}