| | |
help plss..emergency.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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...
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...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
•
•
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...
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
JavaIdiot
•
•
Join Date: Oct 2006
Posts: 101
Reputation:
Solved Threads: 4
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?
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?
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 JavaIdiot
•
•
Join Date: Oct 2006
Posts: 101
Reputation:
Solved Threads: 4
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 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.
•
•
•
•
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
tictactoe.repaint();
JavaIdiot
•
•
Join Date: Oct 2006
Posts: 101
Reputation:
Solved Threads: 4
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
If you send me your code, I'll take a look.
Email is cms271828@yahoo.co.uk
![]() |
Similar Threads
- emergency!!!! (C++)
Other Threads in the Java Forum
- Previous Thread: JFilerChooser default filefilter
- Next Thread: Please Help Stuck Need Help Asap!!!
Views: 1457 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api apple applet application arguments array arrays automation binary blackberry block bluetooth chat class classes client code component database developmenthelp draw eclipse encode error event exception file fractal game gameprogramming givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number object online oracle print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing system template test textfields threads time title transfer tree tutorial-sample update windows working



rep asap..thank u very much :cheesy: .. pls


