Java Part A & B
Java Part A & B
Title - Login and Registration Form using Java AWT and Swing
Java AWT is an API that contains large number of classes and methods to create and manage
graphical user interface (GUI) applications. The AWT was designed to provide a common set of
tools for GUI design that could work on a variety of platforms. The tools provided by the AWT are
implemented using each platform's native GUI toolkit, hence preserving the look and feel of each
platform. This is an advantage of using AWT. But the disadvantage of such an approach is that
GUI designed on one platform may look different when displayed on another platform that means
AWT component are platform dependent.
AWT is the foundation upon which Swing is made i.e., Swing is an improved GUI API that
extends the AWT. But now a days AWT is merely used because most GUI Java programs are
implemented using Swing because of its rich implementation of GUI controls and lightweighted
nature.
The aim of this micro-project is to develop a Login and Registration Form program with
the help of java and AWT command-lines, and implement it successfully. This program is a simple
form page where you can enter your name and select gender using the radio-button and select age
then click on the button. Here you can find different options to select of age among that you can
select anyone.
1
4.0 Literature Review –
In Java, a form for entering authentication credentials to access the restricted page is referred
to as a Login form. A login form contains only two fields, i.e., username and password. Each user
should have a unique username that can be an email, phone number, or any custom username.
After submitting the login form, the underlying code of the form checks whether the credentials
are authentic or not to allow the user to access the restricted page. If the users provide unauthentic
credentials, they will not be able to forward the login form.
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 large set of components which allow a
high level of customization and provide rich functionalities, and is used to create window-based
applications. Java swing components are lightweight, platform-independent, provide powerful
components like tables, scroll panels, buttons, list, color chooser, etc.
In this article, we’ll see how to make Registration form which includes all the buttons and field in
one Form.
1) In this microproject, first of all we have focused on selection of appropriate topic for our micro
project.
2) Select the topic i.e. Login and Registration form using java awt and swing.
3) Then we started with our brief study as well as a survey on our topic.
2
6.0 Resources Required –
3
7.0 Action Plan –
Team Members
Start Date Finish
Date
4
PART B – Micro Project Report
1.0 Rationale
Java AWT is an API that contains large number of classes and methods to create and manage
graphical user interface (GUI) applications. The AWT was designed to provide a common set
of tools for GUI design that could work on a variety of platforms. The tools provided by the
AWT are implemented using each platform's native GUI toolkit, hence preserving the look and
feel of each platform. This is an advantage of using AWT. But the disadvantage of such an
approach is that GUI designed on one platform may look different when displayed on another
platform that means AWT component are platform dependent.
AWT is the foundation upon which Swing is made i.e., Swing is an improved GUI API that
extends the AWT. But now a days AWT is merely used because most GUI Java programs are
implemented using Swing because of its rich implementation of GUI controls and lightweighted
nature.
In Java, a form for entering authentication credentials to access the restricted page is referred
to as a Login form. A login form contains only two fields, i.e., username and password. Each user
should have a unique username that can be an email, phone number, or any custom username.
After submitting the login form, the underlying code of the form checks whether the credentials
are authentic or not to allow the user to access the restricted page. If the users provide unauthentic
credentials, they will not be able to forward the login form.
5
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 large set of components which allow a
high level of customization and provide rich functionalities, and is used to create window-based
applications. Java swing components are lightweight, platform-independent, provide powerful
components like tables, scroll panels, buttons, list, color chooser, etc.
In this article, we’ll see how to make Registration form which includes all the buttons and field in
one Form.
1) In this microproject, first of all we have focused on selection of appropriate topic for our micro
project.
2) Select the topic i.e., Login and Registration form using java awt and swing.
3) Then we started with our brief study as well as a survey on our topic.
4) Then we gathered all information based on the topic of microproject.
6
6.0 Outputs of the Micro Project
Source-Code
Login Form
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class form extends Frame implements ActionListener
{
private Label fname_lbl,lname_lbl,address_lbl,e_mailid_lbl;
private TextField
fname_txt,lname_txt,address_txt,e_mailid_txt; private Button
submit_btn,exit_btn,clear_btn,save_btn; private TextArea
area_txta; public form()
{
setBackground(Color.LIGHT_GRAY);
setLayout(null);
setTitle("Applicatoin Form");
setSize(650,350);
setLocation(100,100);
/*-------------Labels------------*/
address_lbl=new Label("Address");
address_lbl.setBounds(25,200,100,30);
add(address_lbl);
e_mailid_lbl=new Label("E-MailID");
e_mailid_lbl.setBounds(25,250,100,30);
add(e_mailid_lbl);
7
/*---------------TextField----------*/
fname_txt=new TextField();
fname_txt.setBounds(125,100,150,30);
add(fname_txt);
lname_txt=new TextField();
lname_txt.setBounds(125,150,150,30);
add(lname_txt);
address_txt=new TextField();
address_txt.setBounds(125,200,150,30);
add(address_txt);
e_mailid_txt=new TextField();
e_mailid_txt.setBounds(125,250,150,30);
add(e_mailid_txt);
/*-----------------Button------------*/
submit_btn=new Button("Submit");
submit_btn.setBounds(25,300,75,30);
submit_btn.addActionListener(this);
add(submit_btn);
clear_btn=new Button("Clear");
clear_btn.setBounds(125,300,75,30);
clear_btn.addActionListener(this);
add(clear_btn);
exit_btn=new Button("Exit");
exit_btn.setBounds(225,300,75,30);
exit_btn.addActionListener(this); add(exit_btn);
save_btn=new Button("Save");
save_btn.setBounds(450,300,75,30);
save_btn.addActionListener(this);
add(save_btn);
/*--------------TextArea-----------------*/
area_txta=new TextArea();
area_txta.setBounds(350,100,275,180);
add(area_txta);
/*---------------------------------------*/
8
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void paint(Graphics g)
{
g.setFont(new Font("Informal Roman",Font.BOLD,30));
g.setColor(Color.blue);
g.drawString("Application Form",75,80);
g.drawLine(325,25,325,325);
g.drawLine(330,25,330,325);
}
9
e_mailid_txt.setText("
"); area_txta.setText(" ");
}
else if(ae.getSource()==save_btn)
{
try
{
FileOutputStream fos=new FileOutputStream("swati.txt",true);
DataOutputStream dos=new DataOutputStream(fos);
String str2="\n";
String str1=area_txta.getText();
dos.writeChars(str1+str2);
dos.close();
}
catch(Exception e){}
}
}
}
class MyDialog111 extends Dialog implements ActionListener
{ private Label lbl_msg; private
Button btn_yes,btn_no; private Panel
north_panel,south_panel;
public MyDialog111()
{
super(new form(),"Dialog
Demo",true); north_panel=new
Panel(); south_panel=new Panel();
north_panel.add(lbl_msg);
south_panel.add(btn_yes);
south_panel.add(btn_no);
add(north_panel,"North");
add(south_panel,"South");
btn_yes.addActionListener(this);
btn_no.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
10
if(ae.getSource()==btn_yes)
{
System.exit(0)
; } else
dispose(); } }
class IOForm
{
public static void main(String []args)
{
new form().setVisible(true);
}
}
11
Registration Form
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyFrame
extends JFrame
implements ActionListener {
12
12
private String years[]
= { "1995", "1996", "1997", "1998",
"1999", "2000", "2001", "2002",
"2003", "2004", "2005", "2006",
"2007", "2008", "2009", "2010",
"2011", "2012", "2013", "2014",
"2015", "2016", "2017", "2018",
"2019" };
c = getContentPane();
c.setLayout(null);
13
tmno.setFont(
new Font("Arial",
Font.PLAIN, 15));
tmno.setSize(150, 20);
tmno.setLocation(200, 150);
c.add(tmno);
14
year = new JComboBox(years); year.setFont(new
Font("Arial", Font.PLAIN, 15)); year.setSize(60,
20);
year.setLocation(320, 250);
c.add(year);
15
res.setFont(new Font("Arial", Font.PLAIN, 20)); res.setSize(500,
25);
res.setLocation(100, 500);
c.add(res);
setVisible(true);
}
// method actionPerformed()
// to get the action performed // by the user
and act accordingly public void
actionPerformed(ActionEvent e)
{
if (e.getSource() == sub) {
if (term.isSelected()) {
String data1;
String data
= "Name : "
+ tname.getText() + "\n"
+ "Mobile : "
+ tmno.getText() + "\n"; if (male.isSelected())
data1 = "Gender : Male"
+
"\n"; else
data1 = "Gender : Female"
+ "\n";
String data2
= "DOB : "
+ (String)date.getSelectedItem()
+ "/" +
(String)month.getSelectedItem() + "/"
+ (String)year.getSelectedItem()
+ "\n";
16
resadd.setText("");
res.setText("Please accept the"
+ " terms & conditions..");
}
}
term.setSelected(false);
date.setSelectedIndex(0);
month.setSelectedIndex(0);
year.setSelectedIndex(0);
resadd.setText(def);
}
}
}
// Driver
Code class
Registration
{
17
Login Form
Registration Form