Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unless you know how to write a Swing gui program, forget the frame and just use a <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html" rel="nofollow"><strong><code>JOptionPane</code></strong></a>, if all you want to do is put text into a textField. Try this:</p> <pre><code>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(); String s1 = "Thank you for your answer!"; String s2 = "You are "+input+ " years old and you have "+input2+" 2siblings."; JOptionPane.showMessageDialog(null, s1 + "\n" + s2); // pop up dialog } </code></pre> <p><b>Edit:</b></p> <pre><code>public static void main(String[] args) { String age = JOptionPane.showInputDialog(null, "How old are you?"); System.out.println(age); String siblings = JOptionPane.showInputDialog(null, "How many siblings do you have?"); System.out.println(siblings); String s1 = "Thank you for your answer!"; String s2 = "You are "+age+ " years old and you have "+siblings+" 2siblings."; JOptionPane.showMessageDialog(null, s1 + "\n" + s2); // pop up dialog } </code></pre> <p><b>Edit 2: </b></p> <p>I don't want to do it for you, becuase you won't learn that way. So here's a logic step by step of what I would do.</p> <ol> <li>Have a <code>JTextArea</code> to show the conversation</li> <li>Have a <code>JTextField</code> to get the input</li> <li>Have an array of questions</li> <li>Initialize the text area with the first question</li> <li>Get the input from the text field and append that to the text area but save it to a variable first</li> <li>Print the second from the array to the text area.</li> <li>Get the next answer from the text field, save it to a variable and print to text area</li> <li>Make up the final String and append it to the text area.</li> </ol> <p>Note: Each time a the user hits enter in the text field, an index variable should be incremented, as to get the next index in the array of questions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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