Friday, 1 January 2016

How to implement a TextField in java

To implement text field use following code

Code:

import javax.swing.*;
import java.awt.*;
public class JTextClass

{
  public static void main(String[] args)
  {
     JFrame f1;

     f1 = new JFrame("Welcome");

     JLabel l1 = new JLabel("Name");

     JTextField tf1 = new JTextField(20);

     JButton b1 = new JButton("Submit");
 
     f1.add(l1);
     f1.add(tf1);
     f1.add(b1);
     f1.setLayout(new FlowLayout(FlowLayout.LEFT));
     f1.setVisible(true);
     f1.setSize(400,100);
     f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     f1.setLocation(200,200);

    }
 }

Output:


No comments:

Post a Comment