Can a scanner in Java read text from a dialog box

Can a scanner access only from the system console? Can't get from any dialog box?

Thanks.

+5
source share
4 answers

A Scanner can read text from any object that implements Readable .

This includes BufferedReader, CharArrayReader, CharBuffer, FileReader, FilterReader, InputStreamReader, LineNumberReader, PipedReader, PushbackReaderand StringReader(of Readablejavadoc). Unfortunately, this does not include dialog boxes.

Scanner, , Scanner , String, Scanner.

+10

; a Scanner : , InputStreams, ReadableByteChannels, Strings , . . .

+1

, .

String text = input.getText();
Scanner scan = new Scanner(text);
+1

Well, I tried with the example given in the Best way to determine the total word count of a file in Java? : just replace new File("my-text-file.txt")with String variable and it works ...

So, if you get the text content of the component in String, you can use Scanner.

0
source

All Articles