Calculator
Calculator
TUTORIALS FIELD
Home
Tutorials
o
o
o
o
Tech
About
Contact Us
Privacy Policy
Calculator Program in Java Swing/JFrame
with Source Code
by Mehtab Hameed
Hello friends, today we will learn how we can create a Simple
Calculator Program in Java Using Swing with Source Code. This is going
to be our first application using swing programming, where we will
develop a simple calculator using Swing. This is going to be a simple
Java GUI calculator project which will perform basic arithmetic
operations like addition, subtraction, multiplication, division, etc. It can
also be used for finding the square, square root, and reciprocal of any
number.
Before starting this tutorial, I assume that you have the basic concept
of swing components, and also you should have the idea of JButton
Click Event, which means the response of a button when we click on
it. If you already know about the Basics, then we can move ahead to
create a calculator using swing components in Java.
Table of Contents
Related Articles
Simple Calculator Program in Java Using AWT
Login Form in Java Swing
Step 1
Open the NetBeans IDE and then click on the File menu and then
select New Project.
Step 2
Calculator
Progarm in Java Swing – fig – 6
A new window will be opened where you have to give the name
of your Java class (MainClass in this Example).
Then click on the Finish button.
Calculator Progarm in Java Swing – fig – 7
Afterthat, create the main method and create an object of the
Calculator class inside the main method.
1 import javax.swing.*;
2
3 public class MainClass {
4 public static void main(String[] args)
5 {
6 new Calculator();
7 }
8}
After that, we need to run or program. To run our program right
click on the file MainClass.java and then select Run file.
Calculator Progarm in Java
Swing – fig – 8
After Running the Program, you will see the output below.
Simple Calculator Program in Java Using
Swing-fig-9
Now as you can see that we have successfully created our
display.
Now the next thing we have to do is to add components to it.
Adding Components to Our Display Window/Designing
Calculator
Step 3
step 4
1.
JEAN-PAUL
October 23, 2018 at 5:31 am
your are doing a great job…….thanks so much
can i have more of your tutorials ?
Reply
2.
Kelvin K.F. Dennis
February 25, 2020 at 2:28 pm
I love your teaching and I want you to please help me learn more.
Please send me more tutorial.
Reply
Mehtab Hameed
February 25, 2020 at 9:09 am
Thank you so much …I will publish more tutorials as soon
as possible
Reply
Kelvin Dennis
February 25, 2020 at 8:41 pm
Please do it for me. Because I really want to be a
good Programmer. I love your style of coding and
solving problems.
Reply
3.
Aastha
July 31, 2020 at 8:17 am
Hello sir, i have tried creating this code but icons are not coming
in correct positions i have to adjust them manually. Can you
please help??
Reply
Mehtab Hameed
November 1, 2020 at 12:41 pm
Hello Aastha…Thank you for commenting
The program has no Errors …..you can recheck your
program !!
Reply
4.
Anonymous
March 3, 2022 at 3:39 am
Verry helpful. Thank I hope God Bless you.
Reply
Leave a Comment
Comment
Name EmailWebsite
Save my name, email, and website in this browser for the next time I
comment.
Post Comment
Java Swing
Java Environment Setup
JFrame
JLabel
JTextField
JButton
JButton Click Event
JPasswordField
JTable with Database
Registration Form
Splash Screen
Login Form
Text to Speech
Mp3 Player
MS Access Database Connection
Calculator Program
Java
Latest Posts