-
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.
Please help :D - Ian
-
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.
-
Re: Hello Java Forums!
Thanks for that - I am going to have a good play right now over a couple of glasses of wine :) (I'll also post this in the appropriate forum!)
-
Re: Hello Java Forums!
aussiemcgr addressed how a gui might look, but I'm not sure from your question if that's the problem or whether it's the logic (and associated Java constructs) that you are unsure of.
If the latter is the case begin with a command line program ("HelloWorld" extended) which should teach you Java's take "control of flow" constructs and basic i/o.