02-11-2016, 03:43 PM
1463609755-Introduction.docx (Size: 43.18 KB / Downloads: 7)
Introduction
This article explains how to create a Registration Form in a Windows Forms application using Swing in Java. The NetBeans IDE is used to create this application.
Registration Form in Windows Forms application
For creating this application, we need the following files:
1. Java file
2. SQL file
3. odjbc.jar file
4. NetBeans IDE
1. Java File
This Java file is necessary for writing the code. In this file we use Swing components to create a registration form with password validation.
What we can do
A. First we can import several packages.
javax.swing.*;
java.awt.*;
java.awt.event.*;
java.sql.*;
The Swing package is used for the Swing components. All Swing components are defined within this package. The AWT package provides an event handling mechanism, in other words it deals with events like "Button Click". The SQL package creates the JDBC connection.
B. Extends the JFrame components and implements the ActionListener.
Syntax
classEmpSearchApp extends JFrame implements ActionListener
C. Now Declare following components
JLabel l1, l2, l3, l4, l5, l6, l7, l8;
JTextField tf1, tf2, tf5, tf6, tf7;
JButton btn1, btn2;
JPasswordField p1, p2;
D. Now declare Frame components in a default constructor.
Syntax
RegistrationFormApp()
{
..
..
try{
//JDBC CODE
}Catch(Exception ex)
{
System.out.println(ex)
}
..
}
Note: In the dotted part we declare and add various components of Swing; in this part the JDBC code is also used to save user records in a database named "reg". The full code I'll show you below, but here I'll only summarize for you what I can do.
D. Add an ActionListener for the button clicked event
public void actionPerformed(ActionEvent e) {
..
..
}
Note: Since we have multiple buttons we can use "if (e.getSource() == buttonName)".
E. Create main method and run the constructor
Finally, create a main method and run the constructor as in the following:
public static void main(String arr[]) {
new RegistrationFormApp();
}
2. ojdbc.jar file
This JAR file provides a way to set up a Java connection with an Oracle Database. Since the JDBC connection is provided by the Oracle Server vendor, we need to import this JAR file to our library folder.
3. reg.sql table
For fetching records we need a database table; for that we create an "emp" table in our "sandeep" database.
Syntax
reg.sql
create table emp
(
name varchar2(30), email varchar2(40),
pass varchar2(30), count varchar2(30),
state varchar2(30), phone number(15)
);
Now let's start creating this app. Use the following procedure to do that in the NetBeans IDE.