# Registration Form in Windows Form Using Swing in Java

- Link: https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/
- Published: 2019-07-24T22:19:34+05:30
- Author: Ashishkumar Vishwakarma

**Swing** is a part of the **JFC (Java Foundation Classes)**. Building Graphical
User Interface in Java requires the use of Swings. **Swing Framework** contains 
a huge set of components that provide a high level of customization and provide 
smart functionalities and is used to create a window-based applications. Java swing
components are lightweight, platform-independent, provide powerful components like
tables, scroll panels, buttons, lists, color chooser, etc. In this article, we’ll
see **how to make a** Registration Form in Windows Form Using Swing in Java, which
includes all the buttons and fields in one Form.

Also, you can use the Java [compiler](https://www.onlinegdb.com/online_java_compiler)
to compile a program.

### Following are the constructors that can be used to create registration form:

**1-JFrame():** Constructs a new frame that is initially invisible to the user.

**2- JFrame(String title):** Creates a new, initially invisible Frame to the user
with the named given title.

**3- JFrame(String title, GraphicsConfiguration (GC)):** It will create a JFrame
with the specified title and the specified or configured GraphicsConfiguration of
a screen device or monitor.

**4-JFrame(GraphicsConfiguration (GC):** It will create a Frame in the specified
or configured GraphicsConfiguration of a screen device with a blank title.

#### Implementation.

    ```javascript
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class frameDemo extends JFrame implements ActionListener
    {
    	Container c;
    	//creating labels for username & pass resp
    JLabel u=new JLabel("UserName : ");
    JLabel p=new JLabel("Password : ");
    	JLabel su=new JLabel("Success");
    JLabel msg=new JLabel("Invalid username or password");
     	JTextField un=new JTextField();//creating textfield
    JPasswordField pa=new JPasswordField();//creating passwordfield

    Font f=new Font("Arial",Font.BOLD,18);//font dec 
    JButton bt=new JButton("Login");//creating button
    frameDemo()
    {
    c=this.getContentPane();
    c.setLayout(null);
    c.setBackground(Color.YELLOW);
    u.setBounds(100,50,100,40);//set loc & size
    p.setBounds(100,140,100,40);
    un.setBounds(250,50,200,40);
    pa.setBounds(250,140,200,40);
    bt.setBounds(280,250,140,50);
    bt.addActionListener(this);            //assigning event handler to button
    u.setFont(f);
    p.setFont(f);
    c.add(u);//adding to container
    c.add(p);
    c.add(un);
    c.add(bt);
    c.add(su);
    c.add(msg);
    }
    public void actionPerformed(ActionEvent e){
    String user=un.getText();
    String pswd=pa.getText();
    if(e.getSource()==bt)
    	      {                                                      //event handling
    if(user.equals("Ashish")&&(pswd.equals("ash123")))
    {
    su.setBounds(250,320,140,40);
    su.setFont(f);
    }
    else
    msg.setBounds(250,340,200,40);
    msg.setFont(f);
    	     }
    }//END OF METHOD
    }//END OF CLASS
    public static void main(String args[])
    {
    frameDemo frame=new frameDemo();
    frame.setVisible(true);
    frame.setTitle("Login Form");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(100,100,700,500);
    }//END OF METHOD
    }//END OF CLASS
    ```

#### Output.

    ```wp-block-preformatted
     C:\A> javac login.java
    ```

![Registration Form in Windows Form Using Swing in Java](https://technotaught.com/
wp-content/uploads/2019/07/image-49.png)

Registration Form in Windows Form Using Swing in Java

Also View:[ – Write a program to create a registration form using AWT](https://technotaught.com/registration-form/).

Also View- [Write a java program to create a window using swing.](https://technotaught.com/22-write-a-java-program-to-create-a-window-using-swing/)

### Share this:

 * [  X ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=twitter)
 * [  Facebook ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=facebook)
 * [More](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/#)

 * [  WhatsApp ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=jetpack-whatsapp)
 * [  LinkedIn ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=linkedin)
 * [  Email ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?subject=%5BShared%20Post%5D%20Registration%20Form%20in%20Windows%20Form%20Using%20Swing%20in%20Java&body=https%3A%2F%2Ftechnotaught.com%2Fregistration-form-in-windows-form-using-swing-in-java%2F&share=email)
 * [  Reddit ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=reddit)
 * [  Tumblr ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=tumblr)
 * [  Pinterest ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=pinterest)
 * [  Telegram ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/?share=telegram)
 * [  Print ](https://technotaught.com/registration-form-in-windows-form-using-swing-in-java/#print?share=print)

### _Related_
