File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Menu question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Menu question" Watch "Menu question" New topic
Author

Menu question

John Powell
Greenhorn

Joined: Nov 13, 2004
Posts: 11
In the following program the user has a simple menu with 3 choices. Two choices (a & b) will run specific methods and the final choice will quit the program. Is there a simple way to ask the user to press a key (once the called method is done) to return to the main menu, rather than returning automatically?

Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
From a command line, you can't get press ANY key, but you can do press ENTER to continue.



The reason that you can't do any key is that System.in doesn't actually get anything from the commandline until enter is pressed.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

That got me interested...after a bit of googling, this is what I can find -

http://www.javakb.com/Uwe/Forum.aspx/java/3108/JAVA-Unbuffered-access-to-stdin


I'll interpret that to mean that you want to be able to read from
System.in without waiting for the user to press enter - is that right?
If so, it's your OS console, not Java's buffering of System.in that
prevents it, and consequently unbuffering System.in (alone) won't let
you do it.

On unix-like platforms, you can use "stty -icanon min 1" to change
console mode so you can do character-at-a-time input. On other
operating systems, I have no idea.


I tried a few different combinations of input streams, only after using 'stty -icanon min 1' can I read input without waiting for an 'Enter'. This is on linux.

Is this kind of 'unbuffered' input from console enabled by default on windows? I remember writing C programs to read standard input without waiting for an 'Enter' on windows systems.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Menu question
 
Similar Threads
cannot find symbol inside String?
Loop for console input....
Array without ints
Very New To Java Question Help Please!
help with loop