Tuesday, 11 August 2015

How To Create Windows Style Password Screen in Java

In this tutorial we will create windows 8 lock screen in java using netbeans. For creating lock screen  you will need below two pictures and netbeans ide.


FINAL RESULT:

Windows 9 login screen in java


RESOURCES:

   


let's start,open netbeans ide then create a new Jframe form to make this lock screen firstly we need jpanel,jpasswordfield and a jbutton  so pick it from palette and drop in jframe then go to set Layout>>Absolute layout by right clicking on jpanel change variable name of jbutton to "login".




Now its time to set jbutton and jpasswordfield size to do this select any one of them go to properties by right clicking and change the width and size of both according to given pictures.

SIZE OF PASSWORD FIELD:


SIZE OF JBUTTON:




Now select a jlabel from a palette and place in jframe as shown in picture set variable name of this jlabel as "pic" and edit text to null by rightclicking on it.




Go to properties option to change the size of jlabe having name "pic" as shown in picture 



Repeat  a same process this time set variable name of jlabel as a "username" and place it just above of jpanel.



Pick another jlabel and place below a jpanel which will use when password will not match change it's variable name to "error".

Now it's time to our application similar with windows paste a following code in constructor below  initComponents() 

Color c = new Color(0,23,64);
getContentPane().setBackground(c);
jPanel1.setBackground(new java.awt.Color(0,23,64));
jPanel1.setPreferredSize(new java.awt.Dimension(190, 22));
ImageIcon image = new ImageIcon(getClass().getResource("/button.png"));
login.setBackground(new Color(0,0,0,0));
login.setIcon(image);
pic.setIcon(new ImageIcon(getClass().getResource("login.png")));
pic.setSize(159, 167);
username.setFont(new java.awt.Font("Georgia", 1, 18));
username.setForeground(new java.awt.Color(255, 255, 255));
error.setFont(new java.awt.Font("Gisha", 0, 14)); 
error.setForeground(new java.awt.Color(255, 0, 0));
String user="Admin";
username.setText(user);

Our design of lock screen is ready one part of lock screen is left which will detect whether input password is right or wrong first add actionevent on button by right click on jbutton having name login then select events>>Action>>loginActionPerformed  paste a below code in loginActionPerform method.

String pass="123";
String get=password.getText();
if((get.equals(pass)))
{
    error.setText("Correct Password");
    }                                     
else {
    error.setText("Password is incorrect");
}


Our lock screen is completed you can make it more attractive by setting undecorated uncheck.





4 comments:

  1. You have the project for download?

    ReplyDelete
    Replies
    1. No but i will soon upload projects for download.................................

      Delete
  2. Hi,my friend.
    Could you please upload your project.
    thanks man.
    best regard.

    ReplyDelete
    Replies
    1. Hi here are some projects
      http://projavatricks.blogspot.com/2015/10/employee-management-project-in-java.html
      http://projavatricks.blogspot.com/2016/01/tic-tac-toe-game-in-java-fx-for-download.html
      http://projavatricks.blogspot.com/2015/10/anagram-word-puzzle-game-in-java.html
      http://projavatricks.blogspot.com/2015/10/notepad-project-in-java.html

      Delete