File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes TEXT INPUT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "TEXT INPUT" Watch "TEXT INPUT" New topic


K. Joshua Chi

Joined: Jul 31, 2004
Posts: 10
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.

Jay Jay achieves!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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
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

Joined: Dec 10, 2001
Posts: 7023
K. Joshua Chi, you might like to take a look at the example and description I posted in the "How do I....?" thread.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Peter van der Linden
Ranch Hand

Joined: Sep 28, 2004
Posts: 46
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 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.



Author of <a href="" target="_blank" rel="nofollow">Just Java(TM) 2 (6th Edition)</a>
I agree. Here's the link:
subject: TEXT INPUT
It's not a secret anymore!