Creating a Calculator Application

The calculator application enables the end users to perform arithmetic and trigonometric calculations. This application usese java built-in classes and packages to provide various graphic outputs and mathematical results. The calculator application uses the object-oriented concepts and is developed in Java Programming language. This application also uses java file handling to store information about the steps you perform while performing arithmetic calculations. The calculator application makes used of mouse and, keyboard related
methods available in java. The calculator application makes uses several built-in methods of the java string class.

Architecture of the Calculator Application


The Calculator applicaiton uses different classes and packages for different operations. Packages are groups of related classes and interfaces. The eight different java built-in
packages are calculator application are:

java.awt.*;
java.util.*;
java.awt.event.*;
java.applet.*;
java.math.*;
java.io.*;
java.lang.*;
javax.swing.*;

The Calculator application extends the class JApplet and implements three different interfaces. The class JApplet is present inside the package java.applet. The three different interfaces are:
KeyListener
ActionListener

The Calculator application also uses four different user-defined classes for providing arithmatical and trigonometric calculation functionality. The six different calsses are:
Calculator_app
Button_class
Fil_class
Math_class

Packages used in Calculator Application


The java packages used by calculator application have different methods. You need first import the packages in the source code before you can used these packages. You need to used the keyword, import,
to import the package. The import keyword is used to import a particular class or all the classes of the particular package. The different packages used are:

  • java.lang package: Provides classes and interfaces that are used in java program, such as     Object, Class, System, Wrapper, Math and String.

  • java.util package: Provides classes interfaces that support collection of Application Programming Interfaces(API) such as the DAte and Calendar calss in java.

  • java.applet package: Provides functionality for the creation of aplets, such as starting of an applet, stopping of an applet and destroying of an applet.

  • java.awt. package: Provides classes and interfaces that are used for developing a standard GUI progra. The claculator application uses the awt package for creating push buttons, labesl, chaeck boxes and text boxes. The awt package also provides the cotainers panel and frame that are used bye the calculator applicaion.

  • java.io. package: Provides functionality for working with streams. A stream is a sequence of bytes that flows from a source to destination.


Classes used in Calculator Applicaiton
Claculator application uses four different classes. The main() method of Calculator applicatiion is defined in Calculator_app class. The calculator applicaiton also usese the classes, such as Button_class, File_class, Math_class.

Implementing Calculator_app
The class, Calculator_app starts the caculator application. The calculator_app class also declares variables for button, check boxex, text boxex, labesl, panels, checkbox group and strings for the buttons label. The methods declared and used by Calculator_app class are:
public void init()
public void calculate()
public void keyPressed(KeyEvent e)()
public void keyTyped(KeyEvent e)()
public void keyReleased(KeyEvent e)()
public void actionPerformed(AcitonEvent e)

The two inner classes defined by the Calculator class are:
class Button_class extends Button
class File_class

private File_class f = new File_class();//The File_class class in an inner class. The File_class class consists of methods used to work with files.
private ButtonGroup degree_cont;//To group two checkbox options.
private JTextArea textarea1;
private JLabel label1, memoryTagLabel;
private String str="0", str1="", op="", str3="";//Declaring the 5 string variable.
private double m=0, n=0, mem=0;
private JPanel pa1, pa2, pa3, pa4, pa5, pa6, pa7, pa8;//Declaring the eight variable.

//Declaring the label for the button.
private String[] Strbutton = {"Power", "Advanced", "Shift" ,"C" ,"CE" ,"BackSpace" ,"7" ,"8" ,"9" ,"4" ,"5" ,"6" ,"1" ,"2" ,"2" ,"0" ,"." ,"Pie" ,"=" ,"Ans" ,"Sin" ,"Cos" ,"Sqrt" ,"Sqr" ,"X!" ,"Pow" ,"%" ,"1/X" ,"StartStoring" ,"EndStoring" ,"EndStoring" ,"/" ,"Del" ,"Me" ,"-" ,"M+" ,"+" ,"M-" ,"MR" ,"R" ,"Preview" ,"Close"};
private boolean cond = false, cond1=false, cond2=false, cond3=false, cond4=false, cond5=false, pressed=false;

The above listing shows, the declartion and initialisation of different variables used in the calculator application.

 





0 Comments:

Post a Comment