Adding a console to Jframe

Im working on the game right now when he uses the scanner to interact with the user. The game was the first text, so the presentation of the Java console was what I played. Now I need to convert the game to Gui or Jframe, so I want to have the same console function inside the frame, and also use a scanner. Any ideas? Im new when coding, so any help or the same code would be greatly appreciated! Thanks you

+6
source share
2 answers

You can create a graphical interface that looks like a console, for example, using JTextArea to display console text and JTextField , where the user can enter the information they want to send to the console. By adding KeyListener to the JTextField , you can listen to the user by pressing 'Enter' and then send the information to the console.

Instead of reading user input from the console (which sits and waits for the user to finish entering information, then performs an action), you simply listen to the 'Enter' key, and then call the method after going through your "JTextField" Text.

+2
source

There is a lot of interest in this component. Here are a few other SO discussions with good pointers to implement this:

And even more if hints, if you google the terms “swing console” .

+2
source

Source: https://habr.com/ru/post/913678/


All Articles