Im working on a game right now that uses a scanner to interact with the user. The Game was first text based so the Java console view was what i used to play. Now I have to convert the game to a Gui or Jframe so I want to be able to have the same console feature inside the frame while also being able to still use the scanner. Any ideas? Im new at coding so any help or same code will be greatly appreciated! Thank you
You could create a GUI that looks like a console, such as by having a JTextArea
for displaying the console text, and a JTextField
where the user can enter the information they want to send to the console. By adding a KeyListener
to the JTextField
, you can listen for the user pressing 'Enter' and then send the information to the console.
Rather than reading user input from the console (which sits and waits for the user to finish entering the information, then performs an action), you would simply listen for the 'Enter' key and then call a method, passing through your 'JTextField' text.
There is alot of interest in such a component it seems. Here are some other discussions on SO with good pointers for implementing this:
And theres even more if hints if you Google the terms "swing console".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With