Java Swing Program to demonstrate JTextField

Program

import javax.swing.*;
public class JTextFieldDemo
{
	public static void main(String args[])
	{
		JFrame frm = new JFrame("JTextField Demo");
		JTextField txtUserName, txtPassword;
		txtUserName = new JTextField();
		txtUserName.setBounds(0, 0, 100, 20);
		txtPassword = new JTextField();
		txtPassword.setBounds(0, 20, 100, 20);
		frm.add(txtUserName);
		frm.add(txtPassword);
		frm.setSize(300, 300);
		frm.setLayout(null);
		frm.setVisible(true);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

Output

Swing JTextField

Tags: