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.

Hello Java Forums!

Hello gang,

I am looking for some direction - I can program but I am an industrial Engineer and so I program Electronics such as PICs and also lots of PLC Software... I have no Java experience but I used to be quite good with Fortran!

My son has come home from school and he wants to build a decision based text game and so I have committed to assist him build it in Java >.< So I need some pointers - I will be using Netbeans and have a rough understanding of the bare bones of a simple Java program (Hello World!!)

So here is my first question:

I would like to print one of several responses onto the screen based on an answer that I give to a question ie.

Question: You have entered a room, there are 3 doors please choose a door to enter: a) Door to the left, b) Door straight ahead, c) Door to the right

I then input a, b or c and then some text will be printed to the screen.

Re: Hello Java Forums!

I think a moderator will end up moving this out of the Member Introduction area, but I'll give my 2 cents nonetheless. There are several ways you could design something like this.

You could just print out the question with its option in a JLabel, JTextArea, or something and have a JTextField under it for user input. You would then add a JButton for the user to press when they are ready to submit their answer (which you would attach with an action listener that reads the JTextField). Or you could attach a carrot listener to the JTextField that fires as soon as anything is typed in the JTextField (assuming the user input is only one character, there is nothing wrong with that).

Another way I can think of doing it is print out the question without its options in a JLabel, JTextArea, or whatever and have a JList under it with each option. The user could then select the option from the JList, which would then fire a selection listener (or action listener, not sure if JLists support selection listeners) to process the selection the user made.

You can read about all of this stuff by going through the GUI Oracle Tutorials and by doing a bit of trial-and-error.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/