Scanner can only get input from system console? not be able to get from any dialog window?
Thanks.
Scanner can only get input from system console? not be able to get from any dialog window?
Thanks.
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.
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.
Well, I tried with the example given at Best way to determine the total number of words of a file in Java?: just replace new File("my-text-file.txt")
with a String variable, and it works...
So if you get the textual content of the component into a String, you can use Scanner.