Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to simulate or bring console with scanner input into jFrame application
    text
    copied!<p>I would like to bring Console into to jFrame window application with ability to interact with the scanner inputs. Basically, whatever is happening in the console I would like to display it in the application window in the TextArea. Is there a simple solution to that?</p> <p>here's my very simple code</p> <p>ConsoleLogic class:</p> <pre><code>import java.util.Scanner; public class ConsoleLogic { public static void main(String[] args) { System.out.println("How old are you?"); Scanner scanner = new Scanner(System.in); int input = scanner.nextInt(); System.out.println(""); System.out.println("How many siblings do you have?"); int input2 = scanner.nextInt(); System.out.println("Thank you for your answer!"); System.out.println("You are "+input+ " years old and you have "+input2+" 2siblings."); } } </code></pre> <p>ConsoleGui class:</p> <pre><code>import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JTextArea; import javax.swing.JLabel; public class ConsoleGui extends JFrame { private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { ConsoleGui frame = new ConsoleGui(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public ConsoleGui() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblDisplayOutput = new JLabel("Display output:"); lblDisplayOutput.setBounds(22, 25, 124, 16); contentPane.add(lblDisplayOutput); JTextArea textArea = new JTextArea();// ideally I would like to bring // console and the inputs inside // here textArea.setBounds(22, 65, 402, 185); contentPane.add(textArea); } } </code></pre> <p>Many thanks for your help.</p> <p>EDIT: I would like to have something like in this picture:(made in photoshop)</p> <p><img src="https://i.stack.imgur.com/Htdn4.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload