Create Your First GUI Application in Java (Swing)

Console Based Application is what the beginner of the Language is starting with. In order to learn the syntax of a Programming language Like Java, we start from the Console Based Application. I am talking about the Most Common cases. we will come to over topic (Creating GUI Application In Java) but before that let me First Talk a little bit about Console Application.
When we are getting started with the Programming the most common question that comes to ou mind is.

Why we use console base Application?

Console Based Application is Used in very Rare Cases. I will mention a few of them.

  1. Console Based Application is Light Weight.
  2. Console Based Application is Best for Learning Reason. for example when we want to learn about some specific Syntax of the Language we do not have to create a whole Big Program to Learn that The syntax we just Direct Write the Commands and run it and see the result in the shortest possible time.
  3. Console Application is Used in Banks and Other Government Institution for Security Purposes.
  4. Professional Use the Console Based Application to Make it Hard to use for People who do not need it.
  5. There are many more Cases where Console Based Application maybe Helpful. Like it is Easy to Create a Console Base Application. one Other thing about a Console Based Application is it is very robust.

Graphical User Interface

Okay, Enough about Console Based Application. Now let's talk about Graphical User Interface also Called (GUI pronounced is Goyee ) Based Application. The most common type of Computer Application that we do use in our Daily life for Different usual tasks are GUI Based Application. These applications are very powerful and Famous for many reasons. I will discuss a few of them in order to elaborate on the Importance of the GUI based Application.

Why we Use GUI Based Application?

  1. It Provides a User-Friendly Environment for interacting with the Program or Application.
  2. Gui Based Application Provides a Super Attractive Loo and feels to the Application.
  3. Gui Based Application makes the Application Easy to Use for Everyone.
  4. Using the Standards of the GUI Based Application make The user sense of Familiarity with the Application
  5. GUI based Application can Easily be Understand and Can easily be Used.

Now I think these lines is enough to know the Importance of each of the two and lets Come to the Main topic of this Article.

Creating Your First Java GUI Application.

Before Going into the Coding Part note that Java Gui is Based on the Gui Components. these Gui Components are sometimes called Controls or Widgets but the Name is not important, to be honest. What do you think? let me know in the Comment Section. In this post, we will be using Some Basic Component In Java to Create Our First Gui Application.

Test application and Explanation

package AlixaProDev;

// Importing the JFrame and JLabel Component from Swing
// to inherit the Functionality of the JFrame
import javax.swing.JFrame;
import javax.swing.JLabel;

// Importing the Dimension and FlowLayout
// from awt package. (Abstract Windows Toolkit)
import java.awt.Dimension;
import java.awt.FlowLayout;

// Extending the JFrame Class with
public class GuiApp extends JFrame {
        // Create the Jlabel Object
        JLabel label = new JLabel();
        // Set the size of the Jlabel
        // by passing the object of the Dimension
        label.setSize(new Dimension(200,200));
        // setting the Text of the Jlabel
        label.setText("Hello World I am A JLabel.");

        // Most important Step to add our Jlabel
        // to The Frame

        // Setting the Size of the Jframe
        // we can pass the Dimension Object as well
        // By Defalut the Jframe Uses the Border Layout
        // but we can explicitly set it to the Flowlayout
        this.setLayout(new FlowLayout());
        // when the Jframe close the Program will close
        // to make the Jframe Visible

    // main method to make the Object of the Class
    // and run our program
    public static void main (String[] args) {
        new GuiApp();

You can run the above code in your code editor like Intellij IDEA or Maybe Eclipse.

Java GUI Swing

If you have any Questions Please Post it in the Comment Section. Than you For Reading See you in the Next One.

Post a Comment