twc
Posts: 129
Nickname: twc
Registered: Feb, 2004
|
|
Re: How To Get User Input from Command Prompt
|
Posted: Feb 14, 2004 3:09 PM
|
|
There isn't any built-in way to get input from the command prompt. Remember, Java is intended to be cross-platform, and NOT all platforms have a command prompt. This is one of the few areas where older languages, like BASIC, Pascal, or C/C++ have an advantage over Java.
However, since most Java beginners want some way to input from the command prompt, and most of us work on Windows (which does have a command prompt) many people have created custom classes that will do what you are trying to do. The ones that I have seen go by the name Keyboard.java or Console.java. If you do a search for either of those names, you should find something that you can download (usually for free) that will provide the functionality that you are looking for.
Another option is to look at the JOptionPane class. It has several convenient methods that can be used to create input and output dialog boxes. The documentation gives examples of how to use the class. If you haven't bookmarked or downloaded the documentation, I'd do that first.
Since the JOptionPane class is already installed on your computer (assuming that you have version 1.2 or above), using it will mean that you don't have to download anything extra. Of course, you won't have a pure console program any more either.
I hope this helps.
|
|