0% found this document useful (0 votes)
126 views23 pages

Project Report Vipul ND Raghav

This document summarizes a project report for a GUI calculator application created using Java. It includes declarations from the students, a table of contents, and sections on the prologue, introduction, choice of front-end and back-end technologies, hardware and software requirements, screenshots, working of the project, and source code. The project uses Java and Swing for the front-end to create a graphical user interface calculator that can perform basic arithmetic operations like addition, subtraction, multiplication and division.

Uploaded by

Vipul Bhagia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views23 pages

Project Report Vipul ND Raghav

This document summarizes a project report for a GUI calculator application created using Java. It includes declarations from the students, a table of contents, and sections on the prologue, introduction, choice of front-end and back-end technologies, hardware and software requirements, screenshots, working of the project, and source code. The project uses Java and Swing for the front-end to create a graphical user interface calculator that can perform basic arithmetic operations like addition, subtraction, multiplication and division.

Uploaded by

Vipul Bhagia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

PROJECT REPORT ON GUI Calculator

Submitted To: Ms. Binwant Sethi

Submitted By: Raghav Dudeja Vipul Bhagia

DECLARATION

I hereby declare that the project report entitled GUI Calculator which is being submitted in partial fulfillment of the requirement of PTUs 6 weeks post 4th semester summer training is the result of the project carried out by me under the guidance and supervision of Ms. 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)

CONTENTS

SR. NO PARTICULARS
1. 2. 3. 4. 5. 6. 7. 8. Prologue Introduction Choice of Front end and Back end Hardware and Software Requirements Snapshots Working of Project Source Code Epilogue

PROLOGUE
An electronic calculator is a small, portable, usually inexpensive electronic device used to perform the basic operations of arithmetic. Modern calculators are more portable than most computers, though most PDAs are 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.

INTRODUCTION
The project of GUI Calculator deals with the basic calculations encountered in our daily life. Like all other calculator 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

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

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:

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 is SWINGS. 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:

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 subclasses JTextField, 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 of AbstractButton . 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 of AbstractButton . When a checkbox is selected or deselected, an item event is generated. This is handled by itemStateChanged(). Inside itemStateChanged(), the getItem() method gets the JCheckBox object that generated the event.

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.

H/W and S/W Requirements

Following are the hardware and software requirements to run the project successfully:

HARDWARE REQUIREMENTS
1.

PROCESSOR. OPERATING SYSTEM. WIN XP RANDOM ACCESS MEMORY. HARD DISK. MONITOR KEY BOARD.

PENTIUM I or above. Win 95/95/NT 4.5/

2.

3. 4. 5. 7.

32 MB or above. 4 GB or above.

SOFTWARE REQUIREMENTS
1. JAVA

SNAPSHOTS

Invalid calculation (0/0)

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 with it when we press the = button and we get another double variable (q). According to the operator the calculation is performed and we get the desired result in the textfield. In place of the = button we can also use any of the 4 fundamental operator 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.

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<20;i++) { b[i]=new JButton(); b[i].setText(abc[i]); b[i].setFont(new Font("Ariel Black",Font.PLAIN,18)); }

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<20;i++) b[i].addActionListener(this); for(i=0;i<20;i++) p1.add(b[i]); p2.add(p1); p2.add(tf); f.add(p2); f.setVisible(true); f.setSize(300,300); f.setResizable(false); } public void keyPressed(KeyEvent ke) { } public void keyTyped(KeyEvent ke) { if((ke.getKeyChar()!='1')&&(ke.getKeyChar()!='2')&&(ke.getKeyChar()!=' 3')&&(ke.getKeyChar()!='4')&&(ke.getKeyChar()!='5')&&(ke.getKeyChar()!='6') &&(ke.getKeyChar()!='7')&&(ke.getKeyChar()!='8')&&(ke.getKeyChar()!='9')& &(ke.getKeyChar()!='0')&&(ke.getKeyChar()!='.')) ke.consume(); } public void keyReleased(KeyEvent ke) {

public void actionPerformed(ActionEvent e) {

for(i=0;i<=13;i++) { if(e.getSource()==b[i]) { if(i!=3&&i!=7&&i!=11&&i!=12) { if(z==1||z==2||z==3||z==4) { s1=""; z=5; } else s1=tf.getText(); s3=s1+abc[i]; } tf.setText(s3); } } if(e.getSource()==b[16]) { s1=tf.getText(); int t=s1.indexOf('.'); if(t==-1) { s3=s1+abc[16]; tf.setText(s3); } } if(e.getSource()==b[12]) {

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++; }

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);

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;

case 4: r=p/q; } if(k==0) s4=String.valueOf(q); else s4=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(); } }

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 designer 2) 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy