![]() |
| ||
| help plss..emergency. 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: |
| ||
| 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... |
| ||
| Re: help plss..emergency. Quote:
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:) |
| ||
| 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? |
| ||
| Re: help plss..emergency. Quote:
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 |
| ||
| 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 |
| ||
| Re: help plss..emergency. Quote:
tictactoe.repaint(); |
| ||
| 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 |
| ||
| 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 :) |
| All times are GMT -4. The time now is 3:04 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC