• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TEXT INPUT

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
K. Joshua Chi, you might like to take a look at the example and description I posted in the "How do I....?" thread.
 
author
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic