Registration Form in Java | Student registration form using java swing source code

Registration Form in Java Swing is covered in this Post.

To develop this project we used NetBeans IDE.

Steps to develop Registration Form in Java Swing is as below

  1. Create User Interface (UI) Using JFrame
  2. Collect all data in Model sent from UI
  3. Validate and Process Received data
  4. Saving data to MySql Database
Project Explorer for Registration Form

Here we have added three external Jar files

  1. mysql-connector-jar-5.1.14-bin.jar – To connect Java program with MySql Database
  2. jBCrypt-0.4.jar – To encrypt password
  3. jdatepicker-1.3.4.jar– To include date picker in JFrame

To Develop Registration form we are considering example of Student.

We will create basic interface to collect student data in JFrame.

Our Final UI JFrame will as below

Registration Form in Java Swing

1 Create User Interface using JFrame

A. Create a basic structure for frame

In main method we created RegisterFrame class object.

set title, visibility, specified frame coordinated and height and width with bounds and other properties.

Created constructor RegisterFrame() to create and initialize frame components (JLable, JTextBox, JButton, …) .

Method setBounds() is used to set location, width and height of components.

addComponents() is used to add components to Container.

Output of above code is as below

JFrame Basic Size
Fig: JFrame height and width

This is basic layout for our Registration form.

B. Adding Components to JFrame

Components JLabel, JTextField, JRadioButton, JPasswordField, JCombobox, JButton etc are used here.

To select Date from Date Picker additional Jar jdatepicker-1.3.4.jar is added to project.

B Add the basic component in JFrame

  1. Components are Declare as Instance variable
  2. Objects of components are created inside Default Constructor
  3. setBounds() is used to set position ,width and height of components.
  4. addComponents() is used to add components in Container.
  5. addActionListener() is used to add action listener on registerButton.
  6. actionPerformed() is over ridden to handle event

Last two steps are handled later on.

After adding basic components it will create Frame as below

Adding Components in JFrame
Fig: Adding Basic Components in JFrame

C Add JDatePicker in JFrame

First check jdatepicker-1.3.4.jar is added in project

Imports for JDatePicker

Adding JDatePicker in constructor

complete code after adding JDatePicker

DateLabelFormatter class is used to show date selector.

JDatePicker Example
Fig: JDatePicker Addition in JFrame

It will complete our UI

2 Collect all data in Model sent from UI

To collect data Register button is clicked and all data from text box and other input fields are collected and set to student Model.

Lets First See student model

This class contains basic fields of student, constructors, getter and setter methods and to string method.

Adding following code to

  1. ActionLister is added for registerButton
  2. actionPerformed() is overridden to handle click event on register button

Based on genderFemale and genderMale is selected gender set based on that.

Similar way storing programName, branchName and semesterName from respective dropdown list.

To get value from JDatePicker datePicker.getJFormattedTextField().getText() is used.

It returns value in string to convert string date to Date.valueOf(dobString) is used.

3 Validate and Process Received data

Received data is stored in Student object.

We have already validated dob field.

Other fields are validated in

  1. All fields are checked for Empty.
  2. Name length must be more than 4 and less than 20
  3. Validation for Mail id
  4. Mobile Number must be 10 digits long
  5. Password must be between 8 to 20 characters
  6. Password must contain One digit one upper case letter and special symbol
  7. RePassword and password must match

Creating object of validation and and checking for errors if error occurs then it is shown using showMessageDialog().

Processing Data

Processing data is done before and after validation

  1. Based on male and female JRadioButton we assigned male or female to gender variable.
  2. Get Dob from JDatePicker as string and then converted again to java.sql.Date.
  3. BCrypt is used to encrypt password and set to encPassword().

4 Saving data to MySql Database

Validated and processed data and stored in Student object.

To save data of student object first create student table as given below.

This file is used to connect java with database and returns the connection object.

Database name :ebhor
Username: ebhor_user
Password: 21V6

registerStudent() takes a student object and save each field to database using java preparedStatement();

Receiving response from registerStudent().

Finally Saving data on student table

Student Registration Example
Fig: Registration Done
MySql student table perview
Fig: MySql student table perview

How to create a registration form in java swing

The above tutorial explains about to create a registration form in java swing.

How to create a registration form in java using netbeans

Follow the above steps to develop registration form

registration form in java source code download

Read More

  1. JLabel in Java Swing
  2. JComboBox in Java Swing
  3. JTable in Java Swing
  4. JTable Pagination in Java JDBC
  5. Login form in Java Swing
  6. Simple Calculator in Java Applet
  7. Applet Life Cycle in Java
  8. Java program to print vowels in a String

Best Books for Java Beginner to Pro

Head First
Java Complete Reference
Java For Dummy
Effective Java
Let us Java