Java while-loop create text fields from string characters
<p>I'm currently working on text fields, and I'm using <em>NetBeans</em> with Java. The assignment requires a user to enter a sentence. The program reads the sentence, and displays a frame with the sentence that the user entered, but with each character in its own text field. Below is my code along with some comments that point out where I'm getting errors.</p>

<pre><code>package lab.pkg2.pkg2;

import java.awt.FlowLayout;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class Lab22 {

    public static void main(String[] args) {

        // initialize string 
        String str1;

        Scanner sc = new Scanner(System.in); // scanner reads string
        System.out.print("Enter a sentence");
        str1 = sc.next();
        System.out.println(str1);

        // Create frame 
        JFrame frame = new JFrame("Characters in Text field :");
        frame.setLayout(new FlowLayout());

        // Create a text field with a single character
        While(str1 == length) { // error
            JTextField tf = new JTextField(4);
            System.out.print(str1.length());

            String ch = str1;
            tf.setText(String.valueOf(ch));

            str1++; // error
        }

        String ch = str1;
        frame.add(tf); // error

        // make another text field with a single character
        // Set up the frame and displays it
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

    }

}
</code></pre>