this is my 1st time to post. help pls.
can anyone help me program tictactoe (java w/ gui)? req. are comp vs player, player vs player, 2d array, replay, undo..plssss...i need your help :sad: rep asap..thank u very much :cheesy: .. pls:sad:

I think you come to wrong forum. We do not do others people homework/coursework/assigments, we try to help and solve problems with in code you already writen.
So if you did your work and have problem with code, please kindly post your code with problem description and we will try to help you.
Otherwise do your job and come back when you face difficulties...

I think you come to wrong forum. We do not do others people homework/coursework/assigments, we try to help and solve problems with in code you already writen.
So if you did your work and have problem with code, please kindly post your code with problem description and we will try to help you.
Otherwise do your job and come back when you face difficulties...

thank u..ah... yah i have the player vs player...

my prob now is, ... i use mouselistener to add image to the tictactoe(instead of x and o).. i want to know how to remove the image when i click on "new game" button.. what is the syntax and how to remove image...

another prob is how to save the "action" of mouse click..for the replay..or are there any other solution for this? right now im thinking of saving the "action" into a vector.. is this possible?

tyvm:)

Hmmm,

Well I'm assuming you're using JPanel, or extending JPanel and thus using paintComponent(Graphics g) method.

The you draw image using g.drawImage(image,x,y,this);

So to remove the image, I would have some boolean or array that is updated when you press new game, then you can call repaint() on the JPanel object, and if you have some kind of IF statement by the drawImage, you can remove it.

Thats what I would do, how are you actually drawing the images in at the moment?

Hmmm,

Well I'm assuming you're using JPanel, or extending JPanel and thus using paintComponent(Graphics g) method.

The you draw image using g.drawImage(image,x,y,this);

So to remove the image, I would have some boolean or array that is updated when you press new game, then you can call repaint() on the JPanel object, and if you have some kind of IF statement by the drawImage, you can remove it.

Thats what I would do, how are you actually drawing the images in at the moment?

thank you for the answer..hehe.. what i do on "new game" is.. each time i click on the new game button there would be a new frame, but the dispose() method is not functioning,, :( so there are alot of frames..how can i solve this? i want to close the previous frame..

i put
private static JFrame frame = new JFrame ("TicTacToe");under public class

then:
public void actionPerformed(ActionEvent e){
if (e.getActionCommand().equals("New Game")){
// frame.dispose();//is not working..y?
// frame.setVisible(false);not working also..
JFrame frame = new JFrame("Tic-Tac-Toe");
frame.getContentPane().add (new TicTacToe());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
frame.pack();
}

after that:
public static void main (String[] args) {
JFrame frame = new JFrame("Tic-Tac-Toe");
frame.getContentPane().add (new TicTacToe());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
frame.pack();
}

.. im just beginning to learn java :( syntax is so hard

I'm not quite sure what your doing, you seem to be making a new JFrame for each move.
I would just use 1 JFrame containing a JPanel, or object from a class like NoughtsAndCrossesBoard extends JPanel.
Then do all the repainting inside there, you could have an array of 9 ints, each one either 0 for empty, 1 for X, 2 for O.
Then when you repaint, you just read off the array to see what you need.

So when you press new game, you will have:

public void actionPerformed(ActionEvent e)
{
    if (e.getActionCommand().equals("New Game"))
   {
        for(int lp=0;lp<9;lp++) array[lp]=0;
        noughtAndCrossesBoard.repaint();
   }
}

Hope that helps

Edited 3 Years Ago by Dani: Formatting fixed

I'm not quite sure what your doing, you seem to be making a new JFrame for each move.
I would just use 1 JFrame containing a JPanel, or object from a class like NoughtsAndCrossesBoard extends JPanel.
Then do all the repainting inside there, you could have an array of 9 ints, each one either 0 for empty, 1 for X, 2 for O.
Then when you repaint, you just read off the array to see what you need.

So when you press new game, you will have:
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("New Game"))
{
for(int lp=0;lp<9;lp++) array[lp]=0;
noughtAndCrossesBoard.repaint();
}
}

Hope that helps

i got what u mean.ty. but the compiler says that the repint() is a nonstatic method which cant be combine w/ my class tictatactoe

tictactoe.repaint();

thank u.. but i finished it already yesterday except the computer-player :) and it's due today..yeah!! i can have my beauty sleep atlast!! hahaha...joke..

thank u for those who tried to help :)

This question has already been answered. Start a new discussion instead.