Coders Packet

Calculator using Java Swing

By Srikar Vishnu Datta Venkata A

Using Java and swing, a simple calculator app that has basic addition, subtraction, multiplication, division and square root function was implemented.

System requirements:

1. PC with Java compiler.


Required Libraries:

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;



At first, we create a class named calculator. This class extends JFrame class, which is essential to implement a calculator using swings. With the help of JFrame we create a window to display the calculator. Now along with this, our calculator should respond to button click. For this we implement ActionListener interface. 


public class Calculator extends JFrame implements ActionListener {


Now, with the help of JPanel we create the rows (where our buttons will be displayed). Create Buttons with JButton. Now set the font and dimensions for this. To display the result, we use JTextArea. Flow Layout is used to display the rows and Grid Layout to display the result. 

Now create the buttons with action listeners and add them to the row accordingly. Also set the fonts and dimensions for this. 

Finally run this





Square root of 12:

Square root of 12



A simple calculator app was created using Java Swing. 

Download Complete Code


No comments yet