Results 1 to 8 of 8
  1. #1
    Jellybean is offline Member
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default Basic AI using a GUI

    Ok i relatively new to java and i seem fine with the theory of how a program could work but i lack in the actual coding department.That said i have an idea for a simple text based chat input/output program (probably nothing original but oh well).
    I was wondering if i was to explain the theory in the idea and how certain parts would work with different methods (one or two things i still don't quite get but i'm sure the clever people on hear would know) Then someone could put the theory into action and show me the code so i can understand how it would all fit together and work so that i can learn a bit more Java.

    So the idea, as i said its a text based GUi input/output interface consisting of 2-3 panels ontop of each other(North,center,south).

    The first (North) would just be a sill image acting as the programs profile picture (for lack of a better word)-its worth noteing that im not sure if this is possible in java, please let me know.

    The second/third (Center/South) would be the chat.Where you input the text and where it shows the output text. The idea behind this would be an "if else" inside of a "do while" loop e.g. do-ask for input, while- input is not "quit". So that when the user inputs quit they exit the program.
    As for the input/output, this is where the "if else" comes in, each "if" will have a different bit of text so if "input" matches the text then output "reply" e.g. input=hello output = hello, how are you? etc. "else" could be something like "unknown statment" etc.

    This is the second/third because in the interface im not sure if there should be a different panel for the input and the chat history or if it would be better to put them together so you just type underneath the most recent reply.

    I think the sums it up, let me know if something doesn't make sense or anything like that.

    Many thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: Basic AI using a GUI

    Quote Originally Posted by Jellybean View Post
    The first (North) would just be a sill image acting as the programs profile picture (for lack of a better word)-its worth noteing that im not sure if this is possible in java, please let me know.
    It's certainly possible. In fact, there are probably about a dozen different ways to do it. Googling something like "Java display image" will get you a ton of results.

    Quote Originally Posted by Jellybean View Post
    The second/third (Center/South) would be the chat.Where you input the text and where it shows the output text. The idea behind this would be an "if else" inside of a "do while" loop e.g. do-ask for input, while- input is not "quit". So that when the user inputs quit they exit the program.
    As for the input/output, this is where the "if else" comes in, each "if" will have a different bit of text so if "input" matches the text then output "reply" e.g. input=hello output = hello, how are you? etc. "else" could be something like "unknown statment" etc.
    That isn't really how GUIs work. GUIs are *event*-driven, meaning you don't need a do while loop asking for input. You simply ask for input, and then wait for the user to provide input. When the user provides input (that's an event), you can respond to that input and ask for more. I would start with something more basic, just an example program to become more familiar with the concepts- something like a JFrame that shows two JButtons. Clicking one JButton changes the text of the other JButton, and vice versa.

    Your if/else statements might get very long. You might consider using a Map data structure instead.

    Quote Originally Posted by Jellybean View Post
    This is the second/third because in the interface im not sure if there should be a different panel for the input and the chat history or if it would be better to put them together so you just type underneath the most recent reply.
    That's pretty much up to you, but even if you do want them to look like the same component, you'll probably secretly use two components- a JTextArea (or a related component depending on whether you want to support colored text or images in the chat) for the chat area, and a JTextField (or another JTextArea if you want to support multiple lines) for the chat input.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    354
    Rep Power
    5

    Default Re: Basic AI using a GUI

    What you are describing is what is known as a client/server application.
    You are going to want to look into the Swing API to handle the GUI aspect of your application, and Sockets for the actual communication.
    If you aren't very familiar with JAVA, you may want to get the basics down first before you start building the program, but you don't necessarily have to.
    There are a lot of examples on JAVA Client/Server chat applications online that can help you get started.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: Basic AI using a GUI

    Quote Originally Posted by sehudson View Post
    What you are describing is what is known as a client/server application.
    You are going to want to look into the Swing API to handle the GUI aspect of your application, and Sockets for the actual communication.
    If you aren't very familiar with JAVA, you may want to get the basics down first before you start building the program, but you don't necessarily have to.
    There are a lot of examples on JAVA Client/Server chat applications online that can help you get started.
    Sorry, but I disagree completely with this advice (other than the bit about using Swing and starting with the basics). The OP did *not* describe a client/server application. His idea is entirely client-side, with all of the responses hardcoded in if statements (or a Map). They don't come from a server.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    354
    Rep Power
    5

    Default Re: Basic AI using a GUI

    Quote Originally Posted by KevinWorkman View Post
    Sorry, but I disagree completely with this advice (other than the bit about using Swing and starting with the basics). The OP did *not* describe a client/server application. His idea is entirely client-side, with all of the responses hardcoded in if statements (or a Map). They don't come from a server.
    My mistake, I didn't read through the post completely. I saw "simple text based chat input/output program" and made some (incorrect) assumptions about the rest of the post.
    Last edited by sehudson; 01-14-2014 at 03:44 PM.

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,665
    Rep Power
    5

    Default Re: Basic AI using a GUI

    Meh, don't feel bad. We're both having a case of the Tuesdays :/

    Come on brain, work!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Jellybean is offline Member
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default Re: Basic AI using a GUI

    I see, thanks for the help. if its no to much trouble i cant seem to figure out how to set out the if else inside the do while (might not be the best way to do this but its more for the sake of learning than anything else) . could you show me some code that involves it?

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: Basic AI using a GUI

    Quote Originally Posted by Jellybean View Post
    I see, thanks for the help. if its no to much trouble i cant seem to figure out how to set out the if else inside the do while (might not be the best way to do this but its more for the sake of learning than anything else) . could you show me some code that involves it?
    That isn't really how this works- what exactly have you tried? Where exactly are you stuck? Put together a little SSCCE that demonstrates exactly what you've attempted and what you're confused about, and we'll do our best to help you.

    But like I said, a GUI program is going to be different than a command-line program: you probably aren't going to need a do while loop at all.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Need some basic help
    By backdown in forum New To Java
    Replies: 29
    Last Post: 01-20-2011, 04:06 AM
  2. Basic GUI help
    By vahshir in forum New To Java
    Replies: 5
    Last Post: 10-11-2010, 01:33 AM
  3. Need really basic help!
    By anthonyalaan in forum New To Java
    Replies: 9
    Last Post: 09-12-2010, 01:43 PM
  4. Basic Help
    By robjames in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 02:58 AM
  5. Need some really basic help
    By Mayur in forum New To Java
    Replies: 6
    Last Post: 01-24-2009, 06:00 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
  •