How to Create a Password Application In Java

Password login
Image by TBIT – Pixabay

Tutorial On How To Create A Password Application In Java

In this tutorial, I will show you how to create a password application in Java. This application is using JPasswordField class.

The password field, of course, let users to enter a password. And just like every form of password around the world, password field displays echo characters instead of the password itself. The default echo character is a bullet, but you can change that echo character to any character on your keyboard.
Continue reading How to Create a Password Application In Java

The programming language that I specialize in is Java, because I think Java programming language is more universal and of course because I like it regardless of any reason.

How To Create Button In JFrame

Okay, you’ll probably noticed in the title that today we’ll create somewhat a button program or application from scratch. Just like the other tutorial that I’ve  make this tutorial are going to use JFrame as its base. Let’s the code begin !


First of all like other program or application we should import any package or class that we know we would need, as long as the code being worked the import will increase one at a time, here are the first 3 imports :

import javax.*;
import java.awt.*;
import java.awt.event.*;

now let’s make the main class constructor :

public class Button { // well since we’re working with button
}

after that the most importan method of all, the public static void main method :

public static void main(String args){
}

Now the framework are done, we’ll get in bussiness with JFrame. Here we will write the base for our application which is the JFrame, oh yeah after this you need to import the JFrame
(import javax.swing.JFrame) :

      // creates a new JFrame named jframe titled Button (this could be titled anything else)
      JFrame jframe = new JFrame(“Button”); 
        // set the size of the jframe to be : width = 300 & height = 300;
        jframe.setSize(300, 300); 
        // set the visibility of the jframe to true, so it can be seen
        jframe.setVisible(true); 
        // set the jframe close operation
        jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE); 
       

And right now after you wrote all of those JFrame basic, you can run it and will see a frame of an application. But we’re not searching for not only application frame, we’ll make object inside it, in this case a button. So next we need to make a panel that would contain the button, and we’ll also import it
(import javax.swing.JPanel) :

       Panel panel = new JPanel(); // creates the JPanel
       jframe.add(panel); // we add the panel into the JFrame

And now the most anticipated part, we’ll create the button. Just as with JFrame and JPanel we’ll import JButton, and just like JFrame we’ll set the size and visibility, because you know if the visibility is false we won’t be able to see anything (import javax.swing.JButton) :

     // creates the button and set the title to be “Hello World” (you could name this anything else)
     JButton button = new JButton(“Hello World”); 
       // set the visibility of the button
       button.setVisible(true); 
       // set the size of the button
       button.setSize(100, 100);
       // we add the button to be contained by the panel
       panel.add(button); 
      

That’s it right now you just created a button, and this is all the code you’ve just wrotted :

import javax.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;

public class Button {

    public static void main(String args[]){
        JFrame jframe = new JFrame(“Button”);
        jframe.setSize(300, 300);
        jframe.setVisible(true);
        jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE);
      
        JPanel panel = new JPanel();
        jframe.add(panel);
        JButton button = new JButton(“Hello World”);
        button.setVisible(true);
        button.setSize(100, 100);
        panel.add(button);
      
    }  
}

Not bad HUH!!, see you again the next time around. Happy Coding!.

The programming language that I specialize in is Java, because I think Java programming language is more universal and of course because I like it regardless of any reason.