Java program to create an input field on a frame
KW.java
import javax.swing.*;
import java.awt.FlowLayout;
class KW
{
    public static void main(String args[])
    {
        JPanel p=new JPanel();
        FlowLayout fl=new FlowLayout();
        p.setLayout(fl);
        JLabel l=new JLabel("Enter the name ");
        JTextField tf=new JTextField(10);
        p.add(l);
        p.add(tf);
        JFrame f=new JFrame("Frame");
        f.setContentPane(p);
        f.setSize(300,300);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW
Advertisement