943,771 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1688
  • Java RSS
Mar 23rd, 2007
0

help plss..emergency.

Expand Post »
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 rep asap..thank u very much :cheesy: .. pls
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TingTing is offline Offline
7 posts
since Mar 2007
Mar 23rd, 2007
0

Re: help plss..emergency.

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...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Mar 23rd, 2007
0

Re: help plss..emergency.

Click to Expand / Collapse  Quote originally posted by peter_budo ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TingTing is offline Offline
7 posts
since Mar 2007
Mar 24th, 2007
0

Re: help plss..emergency.

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?
Reputation Points: 20
Solved Threads: 4
Junior Poster
cms271828 is offline Offline
123 posts
since Oct 2006
Mar 24th, 2007
0

Re: help plss..emergency.

Click to Expand / Collapse  Quote originally posted by cms271828 ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TingTing is offline Offline
7 posts
since Mar 2007
Mar 24th, 2007
0

Re: help plss..emergency.

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
Last edited by cms271828; Mar 24th, 2007 at 3:46 pm.
Reputation Points: 20
Solved Threads: 4
Junior Poster
cms271828 is offline Offline
123 posts
since Oct 2006
Mar 24th, 2007
0

Re: help plss..emergency.

Click to Expand / Collapse  Quote originally posted by cms271828 ...
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();
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TingTing is offline Offline
7 posts
since Mar 2007
Mar 25th, 2007
0

Re: help plss..emergency.

I'm sure it can, you've just coded it badly.
If you send me your code, I'll take a look.
Email is cms271828@yahoo.co.uk
Reputation Points: 20
Solved Threads: 4
Junior Poster
cms271828 is offline Offline
123 posts
since Oct 2006
Mar 25th, 2007
0

Re: help plss..emergency.

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TingTing is offline Offline
7 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JFilerChooser default filefilter
Next Thread in Java Forum Timeline: Please Help Stuck Need Help Asap!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC