Need help getting started
I need to make a Tic-Tac-Toe game for a Java class. I'm not really sure how to get started (I'm not that great of a programmer). I know I'll need something for a board, marking the board and such, but I'm not sure where to start as far as turning it into code. Here's the basic outline for the project:
Part 1. Write a 3x3 Tic Tac Toe program. Your program must determine when a game terminates. Use a Vector object to represent the Tic Tac Toe board. A user should be able to save the final board configuration to a file for later retrieval and displaying. This can easily be accomplished by serializing and de-serializing the Vector object
Part 2. Add a simple GUI interface to your program using the Swing class library.
Any and all help is greatly appreciated. Thanks in advance.
[815 byte] By [
JC419] at [2007-9-27 20:24:24]

Do you want me to do your homework for you?
The question pretty much tells you what to do there- it should be fairly easy to put this together.
If you can't see how then you probably weren't listening when your teacher gave you the first lesson in software design: Divide and conquer. If a problem appears insurmountable then break it down into smaller problems and break those in turn down until you have a series of bite-size chunks you can do easily.
For more information on object orientation and on using Vectors go to http://www.dickbaldwin.com/tocint.htm - this is an excellent set of tutorials generally- if you go through them you will probably find you can get through most of your class easily.
If you ask people on these forums to do your homework for you they will ignore you. Homework is the only practical experience you will get for a programming course. Take advantage of it. If you want to learn to program do the work, it probably sounds stupid to you right now, but if you end up working as a programmer you will end up regretting not putting more time and effort in when you had the environment and the support, no matter how much you do.
Since this is just a Tic-Tac-Toe game and you must use swing and not any graphic routine, use a JTable. That should get you going.
You can then just fill in an X or O at the appropriate cell location. You could also make each cell a JButton, which will allow you to make it interative, if you went that far. It think it said you have to use a Vector to represent the board. I would've just suggested a 2D array, but a Vector is probably the requirement, so you'll have to translate the Vector data into the 2D game board.
For homework questions, in general, ask questions once you start working on it or get stuck with a design issue or something. If you just post the question as if asking for someone to do the work for you (which I don't think you did in this case, in my opinion), some people are are gonna get ticked off at you.
I think that the easiest approch would be to use a Jframe, setup a gridlayout and add 9 JButtons. Use the same ActionEventHander for each button, but use a value to distinct the buttons from eachother. The ActionEventHandler should:
change the text of the pressed button,
disable it,
check winn situation,
calculate it's own draw,
change the text of it's own button,
disable it,
check win situation.
hlkk at 2007-7-7 1:02:56 >

I definitely wasn't asking for anyone to do my homework, it won't teach me anything. They're not actually teaching us Java, we have to learn it on our own. I'm just not a very good programmer. I was looking for hints like everyone else had posted which is great. No hard feelings? Thanks everyone!
JC419 at 2007-7-7 1:02:56 >

> I definitely wasn't asking for anyone to do my
> homework, it won't teach me anything. They're not
> actually teaching us Java, we have to learn it on our
> own. I'm just not a very good programmer. I was
> looking for hints like everyone else had posted which
> is great. No hard feelings? Thanks everyone!
Well, there's a demo that comes with the SDK in the applets section. Nothing special, but it should give you ideas.
Remember that when you're learning any new language the documentation is your friend. Keep a browser with the Javadocs in it open the whole time.
Actually, my JTable suggestion is probably overkill. Consider a 3x3 gridlayout and jbuttons. Good luck.