Results 1 to 10 of 10
Thread: Ticktacktoe display
- 03-21-2011, 11:09 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Ticktacktoe display
I'm a relative novice to java, and especially swing, and recently decided to try and make a simple ticktacktoe game, no AI, just the basic mechanics.
The board will represented by a two dimensional, 3 x 3, array, with each index representing a square on the ticktacktoe board.
When a space is clicked, either an 'x' or an 'o' is inserted into the corresponding index.
What I'm having trouble with is relating the array to an image of a ticktacktoe board. How will the indexes of the array be related to the squares on the board? When the user clicks a certain square on the board, how will the computer know which index of the array to place a value in?
Apologies if you find this offensively simple.
- 03-21-2011, 11:52 PM #2
Simple Solution
Hey I am not the best in Java so you can use my advice or you can ask someone with more knowledge. However I have just finished developing a 2-player Tic-Tac-Toe game in the NetBeans IDE.
If you are using Netbeans or Eclipse, you can create what is called JFrame and I used 9 buttons to represent the Tic-Tac-Toe board. They all would start out blank, and when you click one of them, it would fire an event which would store the 'X' or 'O' in the corresponding array element as well as set the text of the button to be either an 'X' or an 'O'. Basically, I used different events for each button so I could control where in the array I am storing the data.
If you want to see my code, I can send you the complete NetBeans project so you can look through it but just reply back to this post and tell me whether you use Netbeans or not.
Hope this information helps!
- 03-22-2011, 12:28 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Hmmm, I didn't think to use buttons for each square. Could an image icon possibly be added to each button to make it look a little nicer?
-
If you want to learn GUI and Swing programming then I strongly urge you not to use NetBeans drag-and-drop code generation to generate your GUI as this will teach you little. Instead use the Swing tutorials and learn through them. For Tic-Tac-Toe, a 2-D array of JButtons could work well, or an array of JLabels with MouseListeners would work well too. Either way, the buttons or labels would likely be held in a JPanel that uses a GridLayout(3, 3). I suggest that you give it a try and then if you get stuck, come on back with your code and we can help.
- 03-22-2011, 12:56 AM #5
Member
- Join Date
- Mar 2011
- Location
- Bulacan, Philippines
- Posts
- 23
- Rep Power
- 0
if you want image to use in tic tac toe.. use JLabel and ImageIcon
Keep Moving Forward
- 03-22-2011, 12:58 AM #6
Tic-Tac-Toe
You can use labels, images, or buttons and attach Mouselisteners to them so you can create an event in the background. You should first try it with buttons or labels and move on from there.
If you want to see my code, reply back whether you have Netbeans or not...
- 03-22-2011, 12:59 AM #7
What does creating a JFrame have to do with the IDE? (Answer: nothing at all)If you are using Netbeans or Eclipse, you can create what is called JFrame
db
- 03-22-2011, 01:01 AM #8
I can send you the complete NetBeans project ...Please don't deprive the OP of the opportunity to learn by doing.If you want to see my code ...
db
- 03-22-2011, 01:45 AM #9
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
- 03-22-2011, 02:19 AM #10
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
using display tag in jsp
By Hemant16 in forum Web FrameworksReplies: 1Last Post: 04-21-2011, 12:00 PM -
Display only certain contents of text file and edit display
By blkshrk81 in forum New To JavaReplies: 1Last Post: 12-01-2010, 06:35 PM -
What is the different between Text format display on web browser and display on midle
By Basit781 in forum CLDC and MIDPReplies: 1Last Post: 05-31-2010, 08:46 AM -
How to display a list of items and on click display subitems?
By mandyj in forum New To JavaReplies: 8Last Post: 12-29-2008, 07:12 AM -
How to display information about the display device in SWT
By Java Tip in forum SWTReplies: 0Last Post: 06-28-2008, 09:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks