Friday 12 May 2017

Registration form using swings in java

Registration form in java:

In this tutorial you will learn how to make a registration form in java using swings. Swings basically are used to develop desktop based applications for the users. Swings helps in creating beautiful applications that are rich and good enough to represent. With the help of Swings you can easily create attractive desktop based applications. JFrame is a class which is a extended version of java.awt.Frame which support Swings component architecture.

Following are the constructors that can be used to create applications:

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 specified 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 totally blank title.

There are some methods that can be Inherited:
The class inherits methods from the classes given below−

  1. java.awt.Frame
  2. java.awt.Window
  3. java.awt.Container
  4. java.awt.Component
  5. java.lang.Object
In this tutorial the program will be based on registration, the basic fields that that the programs contains are:

  1. Name
  2. Password
  3. Select Country
  4. Gender
  5. Submit Button

Program:

package pac;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.*;
public class resgiter extends JFrame implements ActionListener
{
JLabel l1=new JLabel("NAME");
JLabel l2=new JLabel("PASSWORD");
JLabel l3=new JLabel("SELECT COUNTRY");
JLabel l4=new JLabel("GENDER");
JTextField t1=new JTextField();
JCheckBox c1=new JCheckBox("MALE");
JCheckBox c2=new JCheckBox("FEMALE");
ButtonGroup bg=new ButtonGroup();
JComboBox c=new JComboBox();
JButton b=new JButton("SUBMIT");
JPasswordField p=new JPasswordField();

public resgiter()
{
this.setLayout(null);
this.setVisible(true);
this.setSize(700,600);
l1.setBounds(100,100,200,40);
l2.setBounds(100,200,200,40);
l3.setBounds(100,300,200,40);
l4.setBounds(100,400,200,40);
add(l1);
add(l2);
add(l3);
add(l4);
t1.setBounds(250,100,150,40);
add(t1);
p.setBounds(250,200,150,40);
add(p);
c1.setBounds(250,400,100,40);
c2.setBounds(350,400,100,40);
add(c1);
add(c2);
bg.add(c1);
bg.add(c2);
c.setBounds(250,300,120,30);
c.addItem("INDIA");
c.addItem("AMERICA");
c.addItem("AUSTRALIA");
c.addItem("PHILLIPHINES");
c.addItem("SPAIN");
add(c);
b.setBounds(200,540,100,60);
add(b);
b.addActionListener(this);
}
public static void main(String[] args)
{
new resgiter();
}
public void actionPerformed(ActionEvent ar)
{
if(ar.getSource()==b)
{
this.hide();
String aa=t1.getText();
//new submit_op(aa);
}
}
}


In the above program, we are using labels for labeling some values, TextFields for inputting the values by the user, checkboxes for selecting gender. You can use radio button instead of checkboxes. One thing must be kept in mind while using gender you must place checkboxes to the ButtonGroup, otherwise it will both select the values male as well as gender. The other thing we are using is ComboBox, ComboBox helps in selecting a values from different values. It will create a  drop down list from which you can select one particular value.
There is one submit button on which there is ActionListener applied. When the submit button is pressed, the page will be redirected to the another page called submit_op. This page must be created by you, so that it can be successfully created.

If you want to know about the working of ActionListener, that you can check my previous blog in which ActionListener implementation is given. For your convenience I am pasting the link of ActionListener implementation below, you can check it out:

https://wingsofm.blogspot.in/2017/05/how-to-implement-actionlistener-java.html

ScreenShot:

Registration form using Swings in java

You can check this link for how to do Manipulation using swings.


This link shows how to implement ActionListener in swings:

4 comments:

  1. I really like what you guys are usually up too. This sort of clever work and coverage! Keep up the fantastic works guys I've added you guys to my blogroll.nice information about java course

    ReplyDelete
  2. Your program is really usefull to me

    ReplyDelete
  3. Thanks all for your comment. It really motivates me to share my knowledge in a well organized manner so that people can grow in their career.

    ReplyDelete

Oracle / PLSQL: FOR LOOP

set serveroutput on; declare a1 varchar2(100); begin select count(*) into a1 from employees; for i in 1..a1 loop dbms_output.put_line...