Project Report Vipul ND Raghav
Project Report Vipul ND Raghav
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
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.
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.
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 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.
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.
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.
2.
3. 4. 5. 7.
32 MB or above. 4 GB or above.
SOFTWARE REQUIREMENTS
1. JAVA
SNAPSHOTS
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) {
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]) {
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[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.