Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a console to a Jframe

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

like image 880
Andrew Avatar asked Apr 20 '12 01:04

Andrew


2 Answers

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.

like image 67
wattostudios Avatar answered Oct 21 '22 12:10

wattostudios


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".

like image 25
Perception Avatar answered Oct 21 '22 12:10

Perception