project report vipul nd raghav
TRANSCRIPT
-
7/31/2019 Project Report Vipul Nd Raghav
1/23
PROJECT REPORT
ON
GUI Calculator
Submitted To: Submitted By:
Ms. Binwant Sethi Raghav DudejaVipul Bhagia
-
7/31/2019 Project Report Vipul Nd Raghav
2/23
DECLARATION
I hereby declare that the project report entitled GUICalculator which is being submitted in partial fulfillment ofthe requirement of PTUs 6 weeks post 4 th semester summer
training is the result of the project carried out by me under theguidance and supervision ofMs. Binwant Sethi.
I further declared that I or any other person has not previously
submitted this project report to any other institution/university
for any other degree/ diploma or any other person.
Date: 10-7-2012
Place: Amritsar (Vipul Bhagia)
-
7/31/2019 Project Report Vipul Nd Raghav
3/23
CONTENTS
SR. NO PARTICULARS
1. Prologue
2. Introduction
3. Choice of Front end and Back end
4. Hardware and Software Requirements
5. Snapshots
6. Working of Project
7. Source Code
8. Epilogue
-
7/31/2019 Project Report Vipul Nd Raghav
4/23
PROLOGUE
An electronic calculator is a small, portable, usually
inexpensive electronic device used to perform the basicoperations of arithmetic. Modern calculators are more portable
than most computers, though most PDAsare comparable in size
to handheld calculators.
Computer operating systems as far back as early Unix have
included interactive calculator programs such as dc and hoc,and calculator functions are included in almost all PDA-type
devices (save a few dedicated address book and dictionary
devices).
The GUI Calculator made by us using Java programming
language can perform the fundamental arithmetic operations of
addition, subtraction, multiplication and division. In addition to
this it has the square root and percentage functionality found in
most electronic computers.
http://en.wikipedia.org/wiki/Arithmetichttp://en.wikipedia.org/wiki/Arithmetichttp://en.wikipedia.org/wiki/Computerhttp://en.wikipedia.org/wiki/Computerhttp://en.wikipedia.org/wiki/Personal_digital_assistantshttp://en.wikipedia.org/wiki/Personal_digital_assistantshttp://en.wikipedia.org/wiki/Ancient_UNIX_Systemshttp://en.wikipedia.org/wiki/Ancient_UNIX_Systemshttp://en.wikipedia.org/wiki/Dc_%28Unix%29http://en.wikipedia.org/wiki/Dc_%28Unix%29http://en.wikipedia.org/wiki/Hoc_%28programming_language%29http://en.wikipedia.org/wiki/Hoc_%28programming_language%29http://en.wikipedia.org/wiki/Personal_digital_assistanthttp://en.wikipedia.org/wiki/Personal_digital_assistanthttp://en.wikipedia.org/wiki/Personal_digital_assistanthttp://en.wikipedia.org/wiki/Hoc_%28programming_language%29http://en.wikipedia.org/wiki/Dc_%28Unix%29http://en.wikipedia.org/wiki/Ancient_UNIX_Systemshttp://en.wikipedia.org/wiki/Personal_digital_assistantshttp://en.wikipedia.org/wiki/Computerhttp://en.wikipedia.org/wiki/Arithmetic -
7/31/2019 Project Report Vipul Nd Raghav
5/23
INTRODUCTION
The project of GUI Calculator deals with the basic
calculations encountered in our daily life. Like all othercalculator applications the user enters a number then selects
an operand by clicking on it, then enters another number,
clicks on the = button and gets the required answer. The
numbers can be entered using the calculators buttons or the
computer keyboard.Characters other than digits and decimal point are not
allowed to be entered through the keyboard. To calculate
square root of a number a number has to be entered and then
the square root button is to be pressed. To use the percentage
button a number is to be entered(say 200) and a fundamental
operator is to be chosen, after that another number is to be
entered (say 25). On clicking the % button 25 is replaced
by 25% of 200 i.e. 50. After that on clicking the = button
we get the desired result according to the operator selected.
Continuous calculations can also be performed as the
fundamental operator buttons also serve the purpose of =
button
-
7/31/2019 Project Report Vipul Nd Raghav
6/23
CHOICE OF FRONT END AND BACK
END
In this project, JAVA is being used as Front end . there is no back end as
there is no requirement for it in our project.
JAVA:
Java is a computer language which is purely object-oriented. Java has two lives,
one as a stand alone computer language for general-purpose programming and the
other as a supporting language for Internet Programming. The general-purpose
programs are known applications and programs written for Internet are known as
applets.
Various features of Java are:
Compiled and Interpreted:
Java compiler translates sources code into what is known as byte code
instructions. Byte codes are not machine instructions and therefore, in the
second stage, Java interpreter generates machine code that can be directly
executed by the machine that is running the Java program. Thus, Java is both
compiled and an interpreted language.
Platform-Independent and Portable:The most significant contribution of Java is its portability. Java program
can be easily moved from one computer system to another. Changes nad
-
7/31/2019 Project Report Vipul Nd Raghav
7/23
upgrades in operating systems, processors and system resources will not force
any changes in Java programs.
Java ensures portability in two ways, First, Java compiler generates byte code
instructions that can implemented on any machine. Secondly, the size of the
primitive data types is machine-independent.
Object-Oriented:Java is a true object-oriented language. All program code and data reside
within objects and classes. The object model in Java is simple and easy to
extend.
Robust and Secure:Java is a robust language. It provides many safeguards to reliable code.
It has strict compile time and run time checking for data types.
Security becomes an important issue for a language that is used for
programming on Internet. Threat of viruses and abuse of resources is
everywhere. Java not only verifies all memory access but also ensure that no
viruses are communicated with an applet.
Distributed:Java is a distributed language for creating applications on networks. It
has the ability to share both data and programs. Java applications can open and
access remote objects on Internet as easily as they can do in a local system.
This enables multiple programmers at multiple remote locations to collaborate
and work together on a project.
Multithreaded and Interactive:
-
7/31/2019 Project Report Vipul Nd Raghav
8/23
Multithreaded means handling multiple tasks simultaneously. Java
supports multi-threaded programs. We do not have to wait for the application
to finish one task before beginning another. The Java runtime comes with tools
that support multiprocess synchronization and constructs smoothly running
interactive systems.
SWINGS
The most important feature of Java used in this project isSWINGS. Swing is
a set of user interface components that is implemented entirely in Java. Swing
is a set of classes that provides more powerful and flexible components than
are possible with the AWT.
Swings supplies components such as buttons, checkboxes, labels, tabbed panes,
scroll panes, trees and tables.
Swing components are not implemented by platform-specific code. Swings are
entirely written in Java and therefore, are platform-independent.
The various components of Swings are:
-
7/31/2019 Project Report Vipul Nd Raghav
9/23
Icons and Labels:Icons are encapsulated by the ImageIcon class, which paints an icon from
an image. The ImageIcon class implements the Icon interface that declares
various.
Text Fields:The Swing text field is encapsulated by the JTextComponent class, which
extends JComponents. It provides functionality that is common to Swing
text components. One of its subclassesJTextField, which allows you to
edit one line of text.
Buttons:Swings provide the class JButton which provides the functionality of a
push button. JButton allows an icon, a string, or both associated with the
push button. The JButton class, which provides the functionality of a
button, is a concrete implementation ofAbstractButton . When a button is
clicked, an action event is generated. This is handled by actionChanged().Inside actionChanged(), the getSource() method gets the JButton object
that generated the event.
Check Boxes:The JCheckBox class, which provides the functionality of a check box, is a
concrete implementation ofAbstractButton . When a checkbox is selectedor deselected, an item event is generated. This is handled by
itemStateChanged(). Inside itemStateChanged(), the getItem() method gets
the JCheckBox object that generated the event.
-
7/31/2019 Project Report Vipul Nd Raghav
10/23
Radio Buttons:Radio Buttons are supported by the JRadioButton class , which is a
concrete implementations of AbstractButton. Radio buttons must be
configured into a group. If a user presses a radio button that is in a group,
any previously selected button in that group is automatically deselected. The
ButtonGroup class is instantiated to create a button group.
Combo Boxes:Swings provide a combo box (a combination of text field and a drop down
list) through the JComboBox class, which extends JComponent. A Combo
Box normally displays one entry. However, it can also displays a drop-down
list that allows a user to select a different entry.
-
7/31/2019 Project Report Vipul Nd Raghav
11/23
H/W and S/W Requirements
Following are the hardware and software requirements to run the project
successfully:
HARDWARE REQUIREMENTS
1. PROCESSOR. PENTIUM I or above.
2. OPERATING SYSTEM. Win 95/95/NT 4.5/WIN XP
3. RANDOM ACCESS MEMORY. 32 MB or above.
4. HARD DISK. 4 GB or above.
5. MONITOR
7. KEY BOARD.
SOFTWARE REQUIREMENTS
1. JAVA
-
7/31/2019 Project Report Vipul Nd Raghav
12/23
SNAPSHOTS
-
7/31/2019 Project Report Vipul Nd Raghav
13/23
Invalid calculation
(0/0)
-
7/31/2019 Project Report Vipul Nd Raghav
14/23
WORKING OF THE PROJECT
For the layout of the calculator a single frame, 3 panels, 1 text
field and 20 buttons of the swing package have been used. The
1st panel contains the text field, he 2nd the buttons and the 3rd
contains the 1st 2 panels. The buttons have been arranged using a
grid layout for the 2nd panel. Out of the 20 buttons 10 are for the
digits, the remaining are (+), (-), (*), (/),(.),(=),(%), backspace,
clear and square root. The code for layout is written within the
constructor.
The number entered by the user is taken into the text field. It
may be entered either through the keyboard or using the buttons.When the user chooses an operator the text in the text field is
taken and converted to a double value through the
Double.valueOf(str) method and stored in a double variable (p).
Then the user enters another number and the same is done withit when we press the = button and we get another doublevariable (q). According to the operator the calculation is
performed and we get the desired result in the textfield. In placeof the = button we can also use any of the 4 fundamentaloperator buttons, thus continuous calculation is performed. The
other operator buttons also work in a similar fashion.
2 interfaces have been used in this, ActionListener and
KeyListener. KeyListener is used to prevent the user from
pressing alphabet or other non numerical character keys except
the decimal point. This has been done using the consume()
method.
-
7/31/2019 Project Report Vipul Nd Raghav
15/23
SOURCE CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
class project1 implements ActionListener,KeyListener
{
JFrame f;
int flag,i,z=5,k=0,len2;
char c2=247;
double p=0,q,r,s;
JPanel p1,p2,p3;
JTextField tf1;
JButton b[]=new JButton[20];
JTextField tf;
GridLayout g;
String abc[]={"1","2","3","+","4","5","6","-
","7","8","9","X","C","0","=",String.valueOf(c2),".","%", "\u2190","\u221A"};
String s1=" ",s3,s4;
project1(){
p2=new JPanel();
p1=new JPanel();
f=new JFrame("Calculator");
tf=new JTextField(40);
tf.addKeyListener(this);
for(i=0;i
-
7/31/2019 Project Report Vipul Nd Raghav
16/23
g=new GridLayout(5,4);
p1.setLayout(g);
p2.setLayout(null);
p1.setBounds(10,60,275,200);
tf.setBounds(30,10,235,40);
for(i=0;i
-
7/31/2019 Project Report Vipul Nd Raghav
17/23
}
public void actionPerformed(ActionEvent e)
{
for(i=0;i
-
7/31/2019 Project Report Vipul Nd Raghav
18/23
k=0;
z=0;
r=0;
p=0;
q=0;
s4="";
tf.setText("");flag=0;
}
if(e.getSource()==b[3])
{
calc();
p=Double.valueOf(tf.getText());
flag=1;
z=1;
k++;
}
if(e.getSource()==b[7])
{
calc();p=Double.valueOf(tf.getText());
flag=2;
z=2;
k++;
}
if(e.getSource()==b[11])
{
calc();
p=Double.valueOf(tf.getText());
flag=3;
z=3;
k++;
}
-
7/31/2019 Project Report Vipul Nd Raghav
19/23
if(e.getSource()==b[15])
{
calc();
p=Double.valueOf(tf.getText());
flag=4;
z=4;k++;
}
if(e.getSource()==b[17])
{
s=Double.valueOf(tf.getText());
q=p*s/100;
s4=String.valueOf(q);
len2=s4.length();
if((s4.substring(len2-2,len2)).equals(".0"))
s4=s4.substring(0,len2-2);
tf.setText(s4);
}
if(e.getSource()==b[18]){
s1=tf.getText();
s1=s1.substring(0,s1.length()-1);
tf.setText(s1);
}
if(e.getSource()==b[19])
{
p=Double.valueOf(tf.getText());
p=Math.sqrt(p);
s4=String.valueOf(p);
len2=s4.length();
if((s4.substring(len2-2,len2)).equals(".0"))
s4=s4.substring(0,len2-2);
-
7/31/2019 Project Report Vipul Nd Raghav
20/23
tf.setText(s4);
z=5;
}
if(e.getSource()==b[14])
{
calc();
k=0;
}
}
public void calc()
{
q=Double.valueOf(tf.getText());
if(flag==4&&q==0)
{
if(p==0)
JOptionPane.showMessageDialog (null, "This value is indeterminate" );
else
JOptionPane.showMessageDialog (null, "Infinity" );
tf.setText("");
k=0;flag=0;
}
else
{
switch(flag)
{
case 1:
r=p+q;
break;
case 2:
r=p-q;
break;
case 3:
r=p*q;
break;
-
7/31/2019 Project Report Vipul Nd Raghav
21/23
case 4:
r=p/q;
}
if(k==0)
s4=String.valueOf(q);
elses4=String.valueOf(r);
len2=s4.length();
if((s4.substring(len2-2,len2)).equals(".0"))
s4=s4.substring(0,len2-2);
tf.setText(s4);
}
}
public static void main(String []a)
{
project1 obj= new project1();
}
}
-
7/31/2019 Project Report Vipul Nd Raghav
22/23
EPILOGUE
As no system design is ever perfect as communication problems,
programmers lack of knowledge or time constraints create errors. A perfect
project is that in which there are minimum number of errors, one which has
the simplest and most concise source code, which is user friendly and
handles exceptions properly. The number and nature of errors in the design
depends on several factors.
Some of the responsible factors are: -
1) Communication between the user and the designer2) The programmers ability to generate a code that reflects exactly the
system Specifications
3) The time frame for the design
In this Project, we have tried our best to cover each aspect carefully and accurately.
On further analysis the drawbacks of this system may show themselves, which may
further require modifications.
-
7/31/2019 Project Report Vipul Nd Raghav
23/23