Basic Tutorial - How To Make Simple GUI Using Java Swing

in #utopian-io7 years ago (edited)

What Will I Learn?

  • You will learn about GUI
  • You will learn about Swing
  • You will learn about Java programming

Requirements

Difficulty

  • Basic

Tutorial Contents

In this post I will explain about making GUI look using java swing. The way to make it too simple, you do not need to design the look of the GUI as do people in general.

Before that you should know what the GUI understanding is. GUI is an interface display, so it can facilitate the user. So, the GUI is a means for the user to be able to communicate with the computer.

To create a GUI, you can use Java Swing. Java Swing is a library in java that serves to create the interface (GUI).

How to make it is like the following steps.

Input command to call Java Swing library, otherwise you will not be able to create GUI.

import javax.swing.JOptionPane;

The next step is to enter the name of the class we want, for example I will give the name javaswing.
The name of this class also serves as the name of the java file that we will save.

public class javaswing 
{

Then, we will enter the command for the main method. This is an obligation for java programming.

public static void main (String[] args) 
{

Next we will declare the name and age variables. Variables serve to accommodate data input. And the data type we use is string, because the data we input is a word or sentence.

String name= " ";
String age= " ";

After making the declaration. We will create the Input Dialog view based on each variable. In this session too, you will be able to start inputting data.

name=JOptionPane.showInputDialog("Submit Your Name = ");
age=JOptionPane.showInputDialog("Submit Your Age = ");

Next, we will declare another variable. The variable we declare contains a sentence for us to display in the output later. Because it contains a sentence, then we use the string data type.

String message="Your Name is " +name +" , And Your Age is " +age;

The last step is to display Message Dialog, here also called the message variable. So it will appear as output.

JOptionPane.showMessageDialog(null,message);
}
}

The result is like the following picture.

  • Inputting name

gambar.png

gambar.png

  • Inputting age

gambar.png

gambar.png

  • Message Dialog View

gambar.png

Here is the complete syntax.

import javax.swing.JOptionPane;
public class javaswing 
{
    public static void main (String[] args) 
    {
        String name= " ";
        String age= " ";
        
        name=JOptionPane.showInputDialog("Submit Your Name = ");
        age=JOptionPane.showInputDialog("Submit Your Age = ");
        
        String message="Your Name is " +name +" , And Your Age is " +age;
        
        JOptionPane.showMessageDialog(null,message);
    }
}



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

This tutorial is quite short, but I will accept it beacuse I believe it holds some value to the community. That being said, please make your future tutorials a little bit longer, either by creating a more complex GUI or handling more than one task.

You can contact us on Discord.
[utopian-moderator]

Hey @elfida I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • This is your first accepted contribution here in Utopian. Welcome!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.25
TRX 0.20
JST 0.038
BTC 93864.76
ETH 3457.40
USDT 1.00
SBD 3.78