Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    tabchas's Avatar
    tabchas is offline Member
    Join Date
    Mar 2011
    Location
    Austin
    Posts
    60
    Rep Power
    0

    Default Tic-Tac-Toe Game - New Project

    Hey Guys,

    This post will be dedicated to my new Java Tic-Tac-Toe project. I have already created a Tic-Tac-Toe game in Java but it was not how I wanted it. I want to build a full game that can be posted on my blog as an applet as well as having a good artificial intelligence algorithm along with Networking capabilities for the 2-player mode. If you guys have any advice, please tell me. I will post questions along the way of the project right here.

    Thanks!
    Tabish Chasmawala

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

    Default

    Okay... so first thing I want to do is design a GUI. My problem currently is that I plan on drawing the 4 lines on a JPanel and then adding it to a JFrame. However, How do I know that a user has clicked within the boxes spaced out between the lines? Do I look for mouse presses? What is the best way to do this?

    Thanks!
    Tabish Chasmawala

  3. #3
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Have you considered using just buttons? 9 buttons that have a preferred size and nothing in them until clicked. Using logic to see whose turn it is and change the label to the X or the O. A basic if statement would handle this nicely.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default

    How do I know that a user has clicked within the boxes spaced
    The mouse click event has the x,y location of the click.
    If you use components for the boxes (vs drawing some lines), then you could register listeners for each component. The clicked component could report that it was clicked on.

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

    Default

    Yea I made my previous Tic-Tac-Toe game with 9 Buttons but I thought it may look nicer to use something like boxes as mentioned. I will try to use boxes as a component and see how it works.

    Thanks for the advice!
    Tabish Chasmawala

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

    Default

    I have another question though. Its about JPanel and JFrame. I have read quite a bit about the two but maybe a little explanation will help clarify the difference between the two. What are the differences between them? Can i draw using Graphics objects on both of them? Why do I have to use both? When should I use which one?

    Thanks!

    P.S. I plan on asking a lot of questions because usually a quick explanation supplements and clarifies whatever I read online or in a book. This project is supposed to be a good learning experience because I am dealing with many topics (AI Design, Multithreading, Networking, GUI Design, etc.)
    Tabish Chasmawala

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default

    For the best answers to these questions, read the Tutorial.
    The Really Big Index
    Go to this site and Search for Creating a GUI.

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

    Default

    Basically, I created a new JPanel Form in Netbeans and adding all my components to it. I then created an instance of it in the JFrame Form code and added it to the JFrame using the method "this.setContentPane(panel)". Why when I used "this.add(panel)" I was not able to see the components set in the JPanel?
    Last edited by tabchas; 07-28-2011 at 06:34 AM.
    Tabish Chasmawala

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

    Default

    Don't use a visual designer. They're not beginners' tools.

    db

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

    Default

    Wait I don't get it. Aren't the visual designers made to help programmers design their programs quicker and easier?
    And what do you mean that they're not beginners' tools?
    Tabish Chasmawala

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

    Default

    Quote Originally Posted by tabchas View Post
    Wait I don't get it. Aren't the visual designers made to help programmers design their programs quicker and easier?
    And what do you mean that they're not beginners' tools?
    They work well for creating the most basic of programs, but the minute you want to create a GUI with even the slightest complexity (as will happen very quickly) and are required to tweak the designer, they become very difficult to use. They also slow down your learning of how Swing works -- the very knowledge necessary for tweaking the designer. I agree with Darryl, learn to do Swing by hand first, and then if you want use a visual designer.

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

    Default

    Okay then... I will try it manually and tall you guys what happens!

    Thanks for the advice!
    Tabish Chasmawala

  13. #13
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Not to mention designers are set to use terrible variable names, whats the point on using a bunch of variables named panel1, panel2, panel3?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

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

    Default

    Yea but you can change the variable names...
    Tabish Chasmawala

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

    Default

    So I was reading on Layout Managers and I think I understand how they work. One question I have though is do I create multiple Panels for each group of components and then arrange the panels on the JFrame? For example, the Tic-Tac-Toe Project has two checkboxes on the side as well as two buttons. Do I put the Tic-Tac-Toe board in one panel with the GridLayout and make a seperate Panel for the other components using a FlowLayout (I would need to organize it by FlowLayout)?
    Tabish Chasmawala

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

    Default

    Quote Originally Posted by tabchas View Post
    ...do I create multiple Panels for each group of components and then arrange the panels on the JFrame? For example, the Tic-Tac-Toe Project has two checkboxes on the side as well as two buttons. Do I put the Tic-Tac-Toe board in one panel with the GridLayout and make a seperate Panel for the other components using a FlowLayout (I would need to organize it by FlowLayout)?
    Using multiple panels has worked well for me. I also tend to avoid using FlowLayout (but still use it sometimes) as it is somewhat limited in its abilities.

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

    Default

    Can anyone explain to me the use of SwingUtilities when running a JFrame? I dont really understand and have read a little about it online. The mention of an Event Dispatch Thread seemed like it was what the code was doing. Any example code I can look at? I really need to know what it does so maybe you guys can give me a brief lesson on it. Is it necessary to use this SwingUtilities.invokeLater? Why is it better to use this code?
    Tabish Chasmawala

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

    Default

    Well I guess nobody knows how to use it. :)
    Anyways, I have created the GUI completely using the GridLayout and have created methods to start, reset, and end game as well as adding a couple of other features like a KeyListener. Now my next target, which seems to be the toughest is the AI for the 1st player mode. Any ideas where to start? I have heard the Minimax algorithm was the best algorithm to use but I dont know if I am ready for it. What topics should I know before attempting a very good AI? Do I need to know binary trees, search algorithms, shortest pathfinding in graphs? I have a book called Data Structures and Algorithms in Java and if any of you guys have the book what chapter should I be on to be ready for this challenge?

    Thanks! :
    Tabish Chasmawala

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default

    How do see adding AI to your TTT game?
    Does mean remembering all previous games and not make the same mistake twice?
    Or looking ahead at all the possible next moves and again and again building a tree of all future game positions from this position until there is a winner or draw and then going down the path that leads to your side winning.

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

    Default

    Im looking for the second option. The first option may be a little tougher I expect so for now I need a decision maker.
    Tabish Chasmawala

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 06-02-2011, 09:29 AM
  2. New Game Project
    By haxic in forum Java Gaming
    Replies: 1
    Last Post: 06-02-2011, 04:39 AM
  3. New Game Project
    By haxic in forum Java Gaming
    Replies: 2
    Last Post: 06-02-2011, 02:27 AM
  4. Replies: 2
    Last Post: 08-05-2010, 04:49 AM

Posting Permissions

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