Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Help with Basic Interface

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Help with Basic Interface

    Ok, basically I've already created my code, and would just like to create a simple GUI to use with it. All I want to do is allow the user to enter a value, have this assigned to a variable, use a switch statement with said variable to call a method, and have the method output the appropriate text to an uneditable window...and repeat the process. Could anyone give me an outline of how this would be accomplished/if it's even possible to do it this way?


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with Basic Interface

    Could anyone give me an outline of how this would be accomplished/if it's even possible to do it this way?
    OK
    allow the user to enter a value, have this assigned to a variable, use a switch statement with said variable to call a method, and have the method output the appropriate text to an uneditable window...and repeat the process.
    Take what you have and start organizing it into logical steps. Organize them steps into order. Any order that makes sense in solving the problem. Use the steps as an outline to write code. If you get stuck ask a question. Post the steps and the code-so-far with any error messages.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with Basic Interface

    I wasn't very clear in my question I guess. Basically, I have my program doing exactly what I want it to do. I've been using scanner for user input and pritln for output. But now I want to give it some graphical interface. So all I would like to do is have the value that the user entered into a text field be assigned to a variable, and to have some way of printing text to a text pane. These seem like they should be fairly simple things to do...but I've been unable to find a decent tutorial so far on using Swing.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with Basic Interface

    but I've been unable to find a decent tutorial so far on using Swing
    Your favorite search engine and a little effort will answer that question.

    You are giving good descriptions on what you want done. Have you made a list of steps to follow?

  5. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Command Prompt Like GUI

    I had a thread like this before, however I wasn't very clear and never got my question answered. So I pushed the problem out of my mind. It's now the 11th hour...and I NEED to get something working.
    Let me preface this by saying that I have no interest learning a lot about swing, for now (so don't worry about "spoonfeeding" me)...Now, onto my issue. I've written my code, I'm sure it's terrible, but it works. Now I need a GUI. All I need/Want is the command prompt, without the ugliness. So, all this GUI needs to accomplish is: 1. display certain text to an output screen. 2. take a users input into a box when they hit enter, assign it to a variable, and then use that variable to determine the text displayed. My problem when I tried this was that to get it to work I had to run the entire program on every "enter". I don't know how to explain my problems any more clearly...ask questions, better yet show me how to make a not hideous command prompt. (P.S. I'm using generated code, I know, kill me.)

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Command Prompt Like GUI

    Quote Originally Posted by Nate View Post
    I had a thread like this before, however I wasn't very clear and never got my question answered. So I pushed the problem out of my mind. It's now the 11th hour...and I NEED to get something working.
    Rather than ignore all the discussion there, perhaps it would be best to reactivate that thread and ask for clarification. There's no need to divide a discussion unnecessarily, and in fact some feel that this is unfair to do as it ignores work of volunteers done previously in effort to help you.

    Let me preface this by saying that I have no interest learning a lot about swing, for now (so don't worry about "spoonfeeding" me)...
    I'm not sure what your goal was with the statement above, but I can assure you it is not likely to endear you to folks here or get you better or more help. We are volunteers who love Java and love teaching Java to those who want to learn. If all you want is teh codez, then you have likely come to the wrong place and with the entirely wrong attitude. I am sure that my words will inflame, so we're even I guess. Note that one reason folks avoid spoon feeding is to encourage questions from those who want to learn and discourage folks who just desire to be spoon fed. Most here would greatly appreciate it if you would retract your words above.

    Now, onto my issue. I've written my code, I'm sure it's terrible, but it works. Now I need a GUI. All I need/Want is the command prompt, without the ugliness. So, all this GUI needs to accomplish is: 1. display certain text to an output screen. 2. take a users input into a box when they hit enter, assign it to a variable, and then use that variable to determine the text displayed. My problem when I tried this was that to get it to work I had to run the entire program on every "enter". I don't know how to explain my problems any more clearly...ask questions, better yet show me how to make a not hideous command prompt. (P.S. I'm using generated code, I know, kill me.)
    You've not shown us any of your code, and we're certainly not going to write code for you, so as this question stands, I'm not sure how we can help you.

    --- Update ---

    Moderation: I've taken the liberty of merging your prior similar thread.

    --- Update ---

    Quote Originally Posted by jps View Post
    Your favorite search engine and a little effort will answer that question.

    You are giving good descriptions on what you want done. Have you made a list of steps to follow?
    Good advice, which is a process which helps all of us -- to break down big problems into little solvable steps, and then solve each one, one at a time.

    That, and if you're still stuck, consider creating and posting an SSCCE, a small compilable and runnable example of what you're trying to achieve (and no NetBeans' code for these since they're not for beauty but for testing concepts with the key being *small* programs).

  7. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Command Prompt Like GUI

    I felt that bringing the worthlessness of my previous thread back (not to insult jps at all! More my failure.) was not worth it, but if you think it's better this way, I defer to your judgement. As for my statement about not wanting to learn about swing...poorly worded...again. My intent was to show that I do not know much about swing, and do not have the time right now to learn how to do it myself. I have every intention of learning swing, but now is neither the time nor place. I need a simple solution, which was the main purpose of that sentence. I retract my words about spoon feeding, but would like to point out that just telling me to break my problem down into smaller parts will not help me, I know basic problem solving skills. Now, since my above question was clearly not good enough-I shall try again.

    I'm having trouble figuring out how to organize my code for swing. It seems to be based around the concept of "user does something>code works>result." Unfortunately, this does not fit my needs, I need something more along the lines of "code works>result>user does something>code works>result" and so on. Now, for a specific example. The player is in a room, they can go out the door or the window. I need to call the room method, output the room description and options, wait for the user to input their choice(preferably by allowing them to enter a number, then press enter to confirm it), call the next area based on which choice they make, and so on. Now, most of this I can do (all of it with command prompt). It's the wait for user input that's getting me. First I need some way to halt the program until the user presses the enter key. Then I somehow need to get whatever value they entered to the text field, and assign it to a variable. Without a GUI I can do all of this just by using a variable.

    Hopefully this is specific enough for you guys to help me. By the way, if anything I said sounds insulting or sarcastic, it was not intended to sound that way. Also, semi hacks that are generally considered bad coding practice, are fine with me (for this). This project is going nowhere after this, so it's just a matter of getting it functional.

  8. #8
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default

    I wonder if what you're looking for is a state system, something like that which can be achieved with a state design pattern. This means that depending upon the state that your program is in will determine its behavior. For instance if your program knows that it is in Room 1( its state), then the program will only allow user behaviors that make sense for this state. In other words the program will only allow you to open doors that are present in room 1, and not doors are only available in 2 too.

  9. #9
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with Basic Interface

    Yes, that sounds almost exactly like what I have (except less cumbersome and more useful). But my question is...how can I integrate a GUI into something like that? I'm mainly struggling right now with receiving user input, as explained in greater detail above.
    This is impossible...I honestly do not think this is feasible...feel free to prove me wrong, but eight hours later and I've not gone anywhere.

Similar Threads

  1. Interface
    By Samaras in forum Java Theory & Questions
    Replies: 2
    Last Post: August 4th, 2012, 05:27 PM
  2. Need help with a interface concept
    By drakenlord in forum Object Oriented Programming
    Replies: 2
    Last Post: September 13th, 2011, 02:17 PM
  3. Interface
    By kaasi in forum Member Introductions
    Replies: 4
    Last Post: April 21st, 2011, 10:45 AM
  4. interface
    By nasi in forum Object Oriented Programming
    Replies: 5
    Last Post: September 2nd, 2010, 10:36 PM
  5. Need Help on the Interface Function
    By yel_hiei in forum Object Oriented Programming
    Replies: 12
    Last Post: July 29th, 2010, 07:27 AM

Tags for this Thread