How is it possible to add a "Scanner" for a text entry box in Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How is it possible to add a "Scanner" for a text entry box in Java?

I would like such a box, in which you can enter your own name, for example, to be greeted - this time for Java :'D

24th Nov 2019, 9:16 PM
2Beers
2Beers - avatar
2 Answers
+ 1
The wording of your question is a little weird, so my apologies if I answer wrong. If you're asking how to import scanner you type this outside of the class import java.util.Scanner; And to create the scanner object you type this in the main method (or whatever method you're using it in): Scanner input = new Scanner(System.in);
24th Nov 2019, 10:44 PM
Odyel
Odyel - avatar
+ 1
You can use a TextField or a TextArea class to achieve what you want. TextField can only hold a single line but TextArea can hold multiple lines. Also you have to import applet and awt api. You can then create an instance of the above classes and use setText() and getText().
25th Nov 2019, 1:09 AM
Avinesh
Avinesh - avatar