Create Simple Login Form in Java Without Connecting to Database[With Source Code]
If you guyz are beginners in java, and you want to learn simple jform application with some java swings like jTextbox, jButton, jLabel etc. change their properties and dragging and dropping these controls in your form, Then you are in the right tutorials.
You can write java code in any text editing software but it is difficult because you have to take care of several things, like installing JDK, JRE, changing environment variable, save java program with the name same as the name of the class and also you have to write the code of each and every things, if you don’t know basic about java, you can read this article: click here. So this may be far more difficult for beginners. That’s why we use IDE. in IDE you can drag and drop several controls.
So, First of all you need to have any IDE, like eclipse or netbeans in your System, i am using NetBeans IDE, if you don’t have, Download it from here: CLICK HERE
STEPS:
[sociallocker]
1. Now open Netbeans IDE and click on file > new project. Select categories as java and project as java application from that window:
2. Click next and then give your project name and then click finished.
3. Now right click on your project and select new > JFrame Form:
4. After this new window will appear from this window drag Panel and extend it, and drag two label, two Text Field, one Button and drop to the jframe which will looks like this:
5. You need to change the jlabel Text to username and password, jTextBox Name (Variable Name of textbox) to txtuser, txtpass or something like that so that it’s easy to remember during programming otherwise you may confused which textbox is associated with which label and change the jButton name to btnlogin and Text to login.
6. Double click on the button and write the following piece of code:
String user,pass; user=txtuser.getText(); pass=txtpass.getText(); if(user.equals("admin") && pass.equals("admin")){ JOptionPane.showMessageDialog(null, "username and password matched"); } else{ JOptionPane.showMessageDialog(null, "username and password do not matched"); }
7. To run this program you need to right click on your jframe and click run file as below:
That’s it guyz. This method of creating login form in java is called static method. if you want to create login form which is connected with your database then see these tutorials:
Login form using SQL Server Database: CLICK HERE
Login form using MySQL Database: CLICK HERE
[/sociallocker]
If you are confused then you can watch the following video: