Javatpoint Logo
Javatpoint Logo

Login Form Java

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.

Steps to create login form:

In order to create a login form in Java, we have to follow the following steps:

  1. Create a class that uses the JFrame and ActionListener to design the login form and perform the action.
  2. Create user interface components using swings and awt and add them to the panel.
  3. Override the actionPerformed() method that will call on the button click.
  4. In this method, we will verify the user entered credentials.
  5. Create a new page using JFrame and navigate the user to it if the credentials are authentic.
  6. Else show an error message to the user.

Let's follow the above steps and implement the login form using swing and awt in Java:

LoginFormDemo.java

NewPage.java

Output:

Now, when we run the LoginFormDemo.java class, a panel will be open having the label, text fields, and button. We enter the credentials and hit on the submit button. If the credentials are authentic, the login form will navigate us to the welcome page as described below:

Login Form Java
Login Form Java
Login Form Java




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA