I am writing a program that includes a menu and will do something different for each menu choice, but I am stuck on how to get the menu selection from the user... Thanks in advance!
Joined: Dec 08, 2004
You'll have to post a more detailed question in order to get good replies.
What kind of program? GUI, command line?
I'm assuming it's a GUI program. Have you written the GUI yet? Have you implemented the MenuBar?
There are some good tutorials out there on how to implement MenuBars in a Java GUI.
Joined: Feb 18, 2003
Hi Bowe, If you are using a menu which has menu items (menu = file, menu item= new) you can add the action listener to the menu items and in the actionPerformed() you can check which menu item was clicked and do what you want to do. Hope this helps.
SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Joined: Dec 09, 2004
It is actually an application that has a menu (no GUI). That is my big problem - I have the application so that it prints out the menu, but now I need the user selection to tell the program what to do from there. Thanks.
Joined: Aug 20, 2001
Whht you will want to do is read from System.in in order to do this. It is an InputStream, so check out the java doc for that.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joined: Jan 29, 2003
One thing we all found disappointing the first time is that you can't get a single keystroke menu choice from the user. You have to make the user press Enter to get anything. Reading from the console is just annoyingly fussy enough that you might want to make a little utility class to hold some reusable code. By way of example, think about how you'd make this work:
If you're in JDK 5 see if you can use Scanner instead of BufferedReader. And let me know the answer!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi