System.out.println happens to be the display or print statement of Java for outputting Strings etc. What is the method that enables the user to get data from the user like in forms, or in a program that requires a user to input data. Thanks. Joshua
Jay Jay achieves!
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
For "forms" you're probably talking about Swing or AWT GUI on a fat client, or maybe HTML forms on a web client. These are pretty involved topics. If you want to write programs that just run on your PC, try the Sun Swing Tutorial
For command line programs System.out does the writing, so it makes sense that System.what? will do the reading. You'll have to dig into buffered readers and such to read a line a time from the user. Take a shot at it and post what you come up with. The gang here will help you tweak it from there.
Enjoy exploring!
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
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
For forms (entered data, not optional data), usually a javax.swing.JTextField(), or a javax.swing.JOptionPane.showInputDialog()
for command prompt, go back to the beginner's main page and scroll down to the subject "How do I..." where you'll find a detailed explanation/example
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
K. Joshua Chi, you might like to take a look at the example and description I posted in the "How do I....?" thread.
What is the method that enables the user to get data from the user like in forms, or in a program that requires a user to input data.
Well, those are two different things. Michael already posted the answer for a text field in a GUI (like in Windows Forms).
For a command line program, you can read a line from stdin and parse it to extract a number from it. If you are using Java 5, there's a simpler way. You can use the new class java.util.Scanner. You wrap a scanner around anything that can be a suitable source of chars, such as the input stream System.in. Here's an example:
This is a lot simpler than before! There are nextFOO() methods for each primitive type and for object types that make sense, like String. This isn't raw I/O - the input isn't watched char by cahr, so the user has to type return before any of it is seen.
Anyway, if you are using Java 5, you will enjoy this.
Cheers,
Peter
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0131482114/ref=jranch-20" target="_blank" rel="nofollow">Just Java(TM) 2 (6th Edition)</a>