Java MM
Java MM
Java MM
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. In java, we can develop
the login form by using Swing technology. We implement the LoginFormDemo.java class in
which we create two text fields, i.e., text1 and text2, for setting the username and password. We
also create a button for performing the action. Swing is a Java Foundation Classes [JFC] library
and an extension of the Abstract Window Toolkit [AWT]. Swing offers much-improved
functionality over AWT, new components, expanded components features, excellent event
handling with drag and drop support. Swing has about four times the number of User Interface
[UI] components as AWT and is part of the standard Java distribution. By today’s application
GUI requirements, AWT is a limited implementation, not quite capable of providing the
components required for developing complex GUI’s required in modern commercial
applications. The AWT component set has quite a few bugs and really does take up a lot of
system resources when compared to equivalent Swing resources. Netscape introduced its Internet
Foundation Classes [IFC] library for use with Java. Its Classes became very popular with
programmers creating GUI’s for commercial applications.
● Swing is a Set Of API ( API- Set Of Classes and Interfaces )
● Swing is Provided to Design a Graphical User Interfaces
● Swing is an Extension library to the AWT (Abstract Window Toolkit)
● Includes New and improved Components that have been enhancing the looks and
Functionality of GUI’s
211521104179 VIKNESH K S
● Swing can be used to build(Develop) The Standalone swing GUI Apps Also as
Servlets And Applets
● It Employs model/view design architecture
● Swing is more portable and more flexible than AWT, The Swing is built on top of the
AWT
● Swing is Entirely written in Java
● Java Swing Components are Platform-independent And The Swing Components are
lightweight
● Swing Supports Pluggable look and feels And Swing provides more powerful
components
● such as tables, lists, Scrollpanes, Colourchooser, tabbedpane, etc
● Further Swing Follows MVC
Many programmers think that JFC and Swing is one and the same thing, but that is not so.
JFC contains Swing [A UI component package] and quite a number of other items:
211521104179 VIKNESH K S
must not depend on any non-Java [O/s based) system classes. Swing components
have their own view supported by Java’s look and feel classes
● Pluggable Look and Feel: This feature enables the user to switch the look and feel of
Swing components without restarting an application. The Swing library supports
components look and feel that remains the same across all platforms wherever the
program runs. The Swing library provides an API that gives real flexibility in
determining the look and feel of the GUI of an application
Login forms are used in almost every website and Application. A login form utilizes the
credentials of a user, in order to authenticate their access. It generally consists of the typical
username or email and password. But more fields can be added to improve the site’s security.
These can be in the form of a passcode, PIN number, or a secret phrase. So indeed that a login
form is an important aspect of your site to prevent unauthorized access. A beautiful login page
can also attract a lot of visitors as well.
● Email: This input field is used to take the email as input from the user.
● Password: This input field is used to take the password as input from the user.
● Show Password: This checkbox field is used to display or hide the password to the
user.
By default, it hides the password.
● Sign-in button: This button is used to authenticate and give access to the verified user.
● Forget Username/password?: This link allows the user to change their username or
password in case he/she forgets.
211521104179 VIKNESH K S
● Signup link: This link takes the user to the signup page in case they want to create a
new account.
Ram : 2GB
Instrument : Keyboard
2.1 Algorithm:
STEP 2: Create a class that uses the JFrame and ActionListener to design the login form and
perform the action
STEP 3: Create user interface components using swings and awt and add them to the panel
211521104179 VIKNESH K S
STEP 4: Override the actionPerformed() method that will call on the button click.In this method,
we will Create a class that uses the JFrame and ActionListener to design the login form and
perform the action.
STEP 5: Create a new page using JFrame and navigate the user to it if the credentials are
authentic
Flowchart :
211521104179 VIKNESH K S
CHAPTER 3: SOURCE CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Exception;
class CreateLoginForm extends JFrame implements ActionListener
{
JButton b1;
JPanel newPanel; JLabel userLabel,
passLabel; final JTextField textField1,
textField2;
CreateLoginForm()
{
userLabel = new JLabel();
userLabel.setText("Username");
textField1 = new JTextField(15); passLabel
= new JLabel(); passLabel.setText("Password");
textField2 = new JPasswordField(15);
b1 = new JButton("SUBMIT");
newPanel = new JPanel(new GridLayout(3, 1));
newPanel.add(userLabel); newPanel.add(textField1);
newPanel.add(passLabel);
newPanel.add(textField2); newPanel.add(b1);
add(newPanel,
BorderLayout.CENTER);
b1.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae)
{
String userValue = textField1.getText();
String passValue = textField2.getText();
if (userValue.equals("[email protected]") && passValue.equals("test")) {
NewPage page = new NewPage();
page.setVisible(true);
System.out.println("login sucessfully");
JLabel wel_label = new JLabel("Welcome: "+userValue);
page.getContentPane().add(wel_label);
}
211521104179 VIKNESH K S
else{
System.out.println("Please enter valid username and password");
}
}
}
class LoginFormDemo
{
public static void main(String arg[])
{
try
{
CreateLoginForm form = new CreateLoginForm();
form.setSize(300,100);
form.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
}
class NewPage extends JFrame
{
//constructor
NewPage()
{
setDefaultCloseOperation(javax.swing.
WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Welcome");
setSize(400, 200);
}
}
211521104179 VIKNESH K S
CHAPTER 4: Output
211521104179 VIKNESH K S
Result
Here I have designed a simple forms project.It is fully a automated system for managing the
java database. This system provides a centralized database maintenance and certain easy access
to
211521104179 VIKNESH K S