Results 1 to 10 of 10
  1. #1
    Nostromo is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    tabchas's Avatar
    tabchas is offline Member
    Join Date
    Mar 2011
    Location
    Austin
    Posts
    60
    Rep Power
    0

    Default 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!

  3. #3
    Nostromo is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    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?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  5. #5
    nap_patague is offline Member
    Join Date
    Mar 2011
    Location
    Bulacan, Philippines
    Posts
    23
    Rep Power
    0

    Default

    if you want image to use in tic tac toe.. use JLabel and ImageIcon
    Keep Moving Forward

  6. #6
    tabchas's Avatar
    tabchas is offline Member
    Join Date
    Mar 2011
    Location
    Austin
    Posts
    60
    Rep Power
    0

    Default 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...

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    If you are using Netbeans or Eclipse, you can create what is called JFrame
    What does creating a JFrame have to do with the IDE? (Answer: nothing at all)

    db

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    I can send you the complete NetBeans project ...
    If you want to see my code ...
    Please don't deprive the OP of the opportunity to learn by doing.

    db

  9. #9
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

  10. #10
    Nostromo is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    Alright, thanks, you guys have given me sufficient ideas. I wasn't thinking with the right mindset.

Similar Threads

  1. using display tag in jsp
    By Hemant16 in forum Web Frameworks
    Replies: 1
    Last Post: 04-21-2011, 12:00 PM
  2. Replies: 1
    Last Post: 12-01-2010, 06:35 PM
  3. Replies: 1
    Last Post: 05-31-2010, 08:46 AM
  4. Replies: 8
    Last Post: 12-29-2008, 07:12 AM
  5. Replies: 0
    Last Post: 06-28-2008, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •