Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Acknowledgement of registration form

Almost we have completed all basic java swing components in this java swing
tutorial series .Now it is time to integrate all the basic components together.
Today in this post I’m gone create a registration form using java
swing components. This tutorial will cover all the swing components which I have
already explained. Generally, we use a registration form to register the necessary
details in the database. If you are an absolute beginner in java swing or if you
didn’t go through my previous posts then no need to worry. Here I will be dealing
all the basic java swing components one by one. So let’s start. Before creating a
registration form we should aware of it.

Use JLabel, JTextField, JButton, JRadioButton, JComboBox, JCheckBox and JTextAr


ea for creating a registration form. I have already completed all these
components in this series. When the user fills the necessary detail and clicks on
the submit button, the details will save in a database. For saving, we need to
connect our project from the database. But in this post, I’m not talking about any
databases. Simply I will display all the entered details on the form. We will see the
database connectivity in the upcoming tutorial. That time we will work with the
database.

Importing Necessary Packages

 In java swing, we create a frame using JFrame class which is already defined
in javax.swing package.
 Import the necessary package like javax.swing.* and java.awt.*;
 Create a class with any name and save it using the class name with .java
extension. In my case it is RegForm.java
Step 1: Creating a Frame using JFrame class
 Create an object of the JFrame class and inside its constructor pass some
string to set the title of the JFrame. You can also use setTitle() method to set
the title.
 Set its visibility to true using setVisible() method. This method takes the
only boolean value as the argument. Boolean value true will make it visible
to the screen.
 Now use setBounds() method to set the location and size of the JFrame.
This method takes four integer values as the argument. The first two
arguments are the location which measures the co-ordinate of x and y-axis
respectively. The last two arguments are for size which specifies pixels.
 Use setDefaultCloseOperation() method to exit the Frame when you
terminate the execution. Pass an argument as JFrame.EXIT_ON_CLOSE.
Once the program execution is terminated the background execution will
stop.

Step 2: Setting Background color of the JFrame


 To set the background color of the Frame we need to import the java.awt.*
package. We have already imported.
 Create an object of the Container class.
 Setting layout as null.
 Using setBackground() method I’ve passed the color constant as the
parameter with the color name. The background color will be changed as
yellow.

Step 3: Creating JLabel for Heading Text


 To create a label we use JLabel class. We need to create an object of JLabel
class and using setBounds() method just set its location and size.
 Here we are creating it for heading so it should be in the top center of the
JFrame.
 Here we will require setting the font style and variant for the heading label
so that the font size will be an increase.
 To increase the font size create an object of the Font class and pass three
arguments in its constructor.
 The first argument for Font name.
 Second argument for font variant and
 The third argument for font size
step 4: Creating a JLabel and JTextField for the name.
 Here a JLabel is created using JLabel class. Inside the constructor, I have
passed string within double quotes as Name.
 Using setBounds() method I have specified the location and the size of the
JLabel.
 In the next thing, I have created a JTextField for writing the name and left
blank to its constructor because the name will be entered during the runtime.
 I used setBounds() method for the JTextField to set the location and size.

step 5: Creating a JButton to Submit the Value


 A submit button is created using JButton class.
 Inside its constructor, the text is passed as the name of the button.
 Here cursor effect is set on the button. That means if the mouse will be
hover over the button the default cursor (arrow cursor) will automatically
change as Hand Cursor. So that it will point that there should be the click.

You might also like