2009:October:26(Mon)
Write a basic implementation of Tic-Tac-Toe as follows:JLabel.
ArrayList for this may be good,
but it's actually not necessary.)
GridLayout.
won()
which
checks whether buttons' texts are
equal
and not empty ("")
across any row, column, or diagonal.
actionPerformed():
"X".
won(),
and if it indicates that some player (who should be "X" at this point) won,
then use JOptionPane.showMessageDialog()
to tell the user something
like, "Congratulations, you won!",
and stop.
JButtons;
and add each button that is still enabled
to this ArrayList.
JOptionPane.showMessageDialog()
to tell the user something
like, "Sorry, it's a cat's game."
Random.nextInt()
to choose an element of
that ArrayList randomly.
won(),
and if it indicates that some player (who should be "O" at this point) won,
then use JOptionPane.showMessageDialog()
to tell the user something
like, "The computer won; better luck next time."
TicTacToe.java .