0

Hello, I've been trying recently to find out how to print out text into the screen like from keyboard, that is printing into active window, just like from keyboard port. Is there a premade package/method for that or how do I use the keyboard port?

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by ztini
0

You could make a window by using JFrame from javax.swing.

JFrame window = new JFrame("This is my windows title")

You could use a JTextField so the user can input into the text field.

JTextField UserInput = new JTextField("Text to go inside the textfield, optional")

and you could have a string to get the text of the JTextField.

String s = UserInput.getText()
0

Hello, I've been trying recently to find out how to print out text into the screen like from keyboard, that is printing into active window, just like from keyboard port. Is there a premade package/method for that or how do I use the keyboard port?

what do you mean my print... you mean type? if so what he said^^^ bext time explain better

0

That really depends on where you are taking the keyboard input from.

If you're looking to take it from the console, you can use the Scanner class

Scanner input = new Scanner(System.in);
System.out.print("Input something: ");
String line = input.nextLine();

However, if you want to know each key that entered as its entered, you need to invoke a KeyListener. If you just need the complete input, you can do something similar to what mango posted previously.

0

That really depends on where you are taking the keyboard input from.

If you're looking to take it from the console, you can use the Scanner class

Scanner input = new Scanner(System.in);
System.out.print("Input something: ");
String line = input.nextLine();

However, if you want to know each key that entered as its entered, you need to invoke a KeyListener. If you just need the complete input, you can do something similar to what mango posted previously.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.