Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Scanner in Java read text from a dialog box

Scanner can only get input from system console? not be able to get from any dialog window?

Thanks.

like image 971
user36064 Avatar asked Nov 10 '08 02:11

user36064


People also ask

What can a scanner read Java?

Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings. It is the easiest way to read input in a Java program, though not very efficient if you want an input method for scenarios where time is a constraint like in competitive programming.

Can a scanner scan a String Java?

The Java Scanner class is widely used to parse text for strings and primitive types using a regular expression. It is the simplest way to get input in Java. By the help of Scanner in Java, we can get input from the user in primitive types such as int, long, double, byte, float, short, etc.

Can scanners read strings?

Scanner is simple text scanner which can parse primitive types and strings using regular expressions.


2 Answers

A Scanner can read text from any object which implements the Readable interface.

That includes BufferedReader, CharArrayReader, CharBuffer, FileReader, FilterReader, InputStreamReader, LineNumberReader, PipedReader, PushbackReader, and StringReader (from the Readable javadoc). Unfortunately, that does not include any dialog windows.

The easiest way to hook a dialog window to a Scanner would probably be to build a Scanner using the constructor that takes a String, passing the user input from the dialog directly to the Scanner.

like image 183
Bill the Lizard Avatar answered Oct 05 '22 12:10

Bill the Lizard


No; a Scanner may be created for any number of possible inputs: Files, InputStreams, ReadableByteChannels, Strings, and anything that supports the Readable interface. See the Constructor Summary.

like image 30
Greg Case Avatar answered Oct 05 '22 13:10

Greg Case