Addition/Multiplication of two integer numbers in Java using Graphical User Interface (GUI) using Netbeans with source code free download

In this post I will teach you how you can add two integer numbers in Java using Graphical User Interface. I made it very simple and easy for you.

At the end of this tutorial you will be able create the following Graphical User Interface with many different properties.

I'm using NetBeans IDE (Recommended for you) for this purpose. Just follow the following steps.

Open NetBeans editor and click on new project as shown blow

Select this project as a Java Application and click on next as show blow

After this name your project, what you want. I named is "Addition GUI" as shown in blow fig.

After the creating project make a new JFrame Form Class as show blow in fig.

Name this class (i.e Addition) and a JFrame Form panel create to move forward as shown blow.

Now drag a text field in you frame from Swing Controls as show shown blow

After adding text field perform the following function on it.

  1. Right Click on text field
  2. Press Backspace button to remove all the text from textField
  3. Press Enter to save changes
  4. Re-size it
The blow fig. shows explanation of the above steps

Add another text field and perform same functions as above. Now right click on TextField and change the variable name to num1 and num2 (you can give it any name) respectively as show blow.

Now add two labels for both text fields from Swing Control as show blow

Right click on label and select Exit Text and named it num1 and num2 respectively. After this add a button to perform addition. When user press on the button, the result of two integer number will show to the user. Add Button from Swing Controls and rename it as you did for labels.

Add another label to JFrame Form to show result of two numbers for user and rename it (i.e The result of two numbers is: ). Now you frame is looking attractive as show blow.

Don't worry we are going to the ending stages. Now right click on the Add Button and select Events ->Action -> Action Performed as shown blow.

Now you are in source code inside an Java Method. Paste the blow code into this method.

int value1 = Integer.parseInt(num1.getText());
        int value2 = Integer.parseInt(num2.getText());
        int result = value1 + value2;
        txt_result.setText("The Sum of two numbers is:" + result);

For confirmation see the blow fig.

Line no. 3 and 4 convert values of text fields into integer value to add them. Line no. 7 set the txt_result label (which we were added) to show addition of two number to the user.

Last Stages:  Now open you main class and set the JFrame Form visible using its object name as blow.

Add blow code into your main class.

Addition add = new Addition();

Now you are ready to run this project. Click on the run button and to see your hard-work. A new window will open as shown blow. So now you are able to do any arithmetic operation in Java using GUI.

Click on the download button for full source code.

 Download Now

Note: Please! like, comment and share it with your friends. Thanks! for reading post may be helpful for you.

Post a Comment


  1. Replies
    1. Share this blog with your friends to get interesting offers :)

  2. the program does not apply

    1. What's the problem that you're facing? Did you run the source code? I'll be happy to help you. Please let me know. Thanks!


  3. Why i can't download the file ?