JOptionPane in Java

JOptionPane in Java is used to provide dialog boxes such as message dialog box, input dialog box and confirm dialog box. These dialog boxes are used to get input from user or just to display information.

there are 3 common methods of the JOptionPane which is :

  • showMessageDialog()
  • showInputDialog()
  • showConfirmDialog()
Continue reading JOptionPane in Java

How To Create A Java JTabbedPane

The Java JTabbedPane class is usually used by Java programmers to switch between a group of components. The way you switch between components is by clicking on a tab with a given title or even icon.

Continue reading How To Create A Java JTabbedPane

Java JTable For Listing

Java JTable~Here we’ll create a table or especially a JTable and set a list of people and their Hobby’s. This JTable is really good to use when you have a lot of peoples data to list for. You’ll create it into a form of columns and rows.

Here is the code :

Continue reading Java JTable For Listing

Create A JTree In Java Eclipse

The Java JTree class is usually used to display a tree structured data or a hierarchical structured data.

Of course in a hierarchical structured data, it has a “head” or a top data or a “root”. And in JTree it has a “root node” at the top of the tree data. That is usually the parent for all nodes inside the tree.

Continue reading Create A JTree In Java Eclipse

How To Create TextFileChooser In Java

Back again with another tutorial for Java. Today I’ll show you how to create a TextFileChooser In Java. It’s using Java Swing, and now let’s jump right in :

Continue reading How To Create TextFileChooser In Java

How To Create Java Color Chooser

Create Java Color Chooser

You need to know that Java can do almost about anything when it comes to programming, besides having its weaknesses.

Here is a tutorial on how to create java color chooser using eclipse ide:

Continue reading How To Create Java Color Chooser

Display a Clock In Java Applet

Create a Clock In Java Applet

Now, here we’ll create a clock in java applet. Java method that you first have to understand is :

  • The Thread
  • The Calendar Class, and
  • Graphics g

After that, you can create a clock app just like this :

Continue reading Display a Clock In Java Applet

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

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!.