Calculator App in Java with NetBeans IDE- Source Files

JAVA Calculator

Calculator App developed using java for Java project. This app/program is developed using Netbeans IDE (Integrated Development Environment) software. Netbeans IDE helps coding java applications a lot easier. Made with quite simple logic and works well. However, the coding are not of advanced level nor difficult coding so this should be easier for those who are just beginner.

Some Explanation

In the design, i  made a simple quite calculator like interface which was quite good at final look(Not so much great 🙂 ). I tried to use functions and constructor. To reduce redundant codes that would go same for getting values from the buttons i placed and for arithmetic functions on the Calculator:

Inserting Buttons with Number values and arithmetic operations

Therefore, I placed some textfield and buttons on the first and also named them so that i can remember them easily.

  • Buttons : 0-9 (each with unique variable name)
  • Textfield : One large text field to show input and result
  • Extra buttons for +,-,*,/ And Clear.

Design looks something like this:

Lets code some functions and variables
Global variable with public access

At the coding part, first i made some global variables that would hod the values for our first number, second number ,arth (arithmetic operations) and result;


To make global variable, it has to be defined on the top and public key has to be used to be accessible to all functions ( more info on file).

So the value input on the buttons are extracted as String and we have to convert it into integer later on for arithmetic operations cause we can’t do it if its string.

Extracting Values from Buttons and some conditions

So for getting value from each button, I simply made a function:



This function stores value in num1 and num2.

There is a condition too which checks if the arth variable is empty means num1 has’t been set (simple logic) and puts value in num1 with concatenation else put value in num2.



I used clear function to clear everything on textfield and on variable when there is result while user ends one operation and starts another.

Another arth function is to put operation sign on the variable when users clicks on the corresponding button.

Main arithmetic function of the calculator


The main operation on the Calculator App is operation function which is actually quite simple. This  function it takes three parameter: string a , b ,c ( a= num1 ,b=num2 and c = arth).

Then, it is parsed into double. Also it takes decimal values in case user attempts decimal operations. Finally, executed by a switch function with c which holds “arth” value and decides the case.

Returning value and setting on TextField

The result is returned in double as we defined the double datatype function on the top. And afterwards, setText() is used to display the value in textfield.


Sorry if my phrases are bit confusing, here’s the link to the actual file so that you can understand more by looking at the codes.

So, Download Link is Below:



You may also like...