Date post: | 06-Apr-2018 |
Category: |
Documents |
Upload: | amardeep-singh |
View: | 214 times |
Download: | 0 times |
of 62
8/2/2019 Ship A
1/62
ON
ADVANCE CALCULATORADVANCE CALCULATOR
A
Project Submitted To Punjab Technical University
Study Center, Patiala
In Fulfillment Of The Requirement For M.Sc(I.T)
Session 2009-2010
(4TH Semester)
Under the guidance of
Vipan Batta
Submitted by
SHILPA RANI (9205910557)
PUNJAB TECHNICAL UNIVERSITY
JALANDHAR, PUNJAB
8/2/2019 Ship A
2/62
CERTIFICATE
This is to certify that the project entitled Advance
Calculator is developed and submitted by Shilpa Rani,Mandeep
Kaur,Ramandeep kaur in the partial fulfillment of requirement of
MscIT for session 2009-2010 under the Vaishnoo Maa Computer
Center, Patiala. This project is bonafield record of work carried out by
students during the course of MscIT
It is further certified that this project or part of this project has
not been submitted for the award of any other degree/diploma.
(Mr. Gurpreet Singh)
Manager,
Vaishnoo Maa Computers,
PTU Study Center,
Patiala-147001
8/2/2019 Ship A
3/62
Preface
As a part of the regulations for the grant of the MscIT, the
Vashnoo Maa Computer Center, Patiala requires all the students of
MscIT to submit project.
In the pursuance of the above requirements in the partial
fulfillment of the requirements of the MscIT, we were allotted the
project under the Supervision of Mr Vipan Batta.
We have tried my best to make a good project report.
Information in this project is collected from various books, and with
the help of the teachers.
We also highly thankful to the teachers for providing me
guidance through out the project.
Submitted by
SHILPA RANI (9205910557)
8/2/2019 Ship A
4/62
ACKNOWELDGEMENT
Punjab Technical University, jallandhar is a great education
institute dedicated to the pursuit of academic excellence and
innovations of much college of districts of Punjab state are affiliated
to the privileges of this university. The university has research
teaching departments. There is a well stocked library, spacious
auditorium, centre, space, sports stadium, observatory, art museum
and beautiful botanical gardens.
The faculties of computer center of Punjab Technical University
are of very high quality. Central computer center of university have
the best infrastructure in terms of computer system. Computer center
also maintains the website of university "www.ptu.jal.org". Central
computer center provides the best facilities to the student. Its general
labs remains open for the students from morning to evening
Teacher of the MscIT department provide all kind of help to the
students so that the students may understand the technical aspects of
the subject. There is a library in computer center providing all
necessary books to the student.
We are highly thankful to the teachers, officers and staff of
computer Center.
Punjab Technical University, Jalandhar is providing a great
opportunity through MscIT to students in different faculties to learn
about computer.. We are highly thankful of the University.
SHILPA RANI (9205910557)
8/2/2019 Ship A
5/62
INDEX
1. Certificate
2. Preface3. Acknowledgment
4. hardware and software requirements
5. introduction to project
6. introduction to java
7. source code of the project
8. bibliography
8/2/2019 Ship A
6/62
Introduction to Project
Title: advanced Calculator
Description: This is an advanced scientific calculator version Performs
trigonometric, logarithmic, exponential functions, memory operations.
Also it can store infinite number of values in memory u can view and
copy down the values from memory to your display. it is classical
calculator but has some thing special that you can store your work in
a file in the hard and return to it and work on Keyboard besides we'd
created our own Math functions including sin & cos .
8/2/2019 Ship A
7/62
Introduction to JAVA
Java is a programming language. Developed in the years 1991 to
1994 by Sun Microsystems.Programs written in Java are called
applets. The first browser that could show applets was introduced in
1994, as "WebRunner" - later known as "The HotJava Browser".
You do not need to know Java to install applets on your pages. There
are thousands of free applets available on the internet for almost any
purpose. Most of them can be customized without programming.
Most of today's browsers can run applets. The ones that can't, aren't
of much importance, since very few users have such outdated
browsers. To be more precise, applets can be embedded in pages
viewed by Netscape 2+ and Internet Explorer 3+.
However, some people have turned off the ability to run applets in
their browser. This is in most cases companies with more or less
paranoid ideas of potential hacking.
No matter what their motivation is, it's a fact that there are a minor
amount of people out there, that will not see your applets, even if
their browser is capable of showing it. This should be taken into
consideration before deciding to add applets to your pages.
An applet can be embedded into a webpage. Usually the applet has
several settings that will allow you to personalize it. For instance, if
you insert an applet that will work as a menu, you can specify which
8/2/2019 Ship A
8/62
options should be in the menu, and which pages should be loaded
upon click on an option.
Since Java is a real programming language there aren't many
limitations to it. Any program running on your computer could
possibly have been made as an applet. Spreadsheets,
wordprocessors, graphics programs... even entire browsers could be
made with Java. However, most applets used on webpages serve
much smaller purposes than the ones mentioned. The reason is
simple: They need to be transferred through the internet, and
therefore can't take up just any amount of space.
When you put an applet on your page you will need to save the applet
on your server as well as the HTML page the applet is embedded in.
When the page is loaded by a visitor the applet will be loaded and
inserted on the page where you embedded it.
8/2/2019 Ship A
9/62
The Java Programming Language
The Java programming language is a high-level language that can be
characterized by all of the following buzzwords:
Simple Architecture neutral
Object oriented Portable
Distributed High performance
Mul tithreaded Robust
Dynamic Secure
Each of the preceding buzzwords is explained in The Java Language
Environment, a white paper written by James Gosling and Henry
McGilton.
In the Java programming language, all source code is first written in
plain text files ending with the .java extension. Those source files are
then compiled into .class files by thejavac compiler. A .class file does
not contain code that is native to your processor; it instead contains
bytecodes the machine language of the Java Virtual Machine1 (Java
VM). Thejava launcher tool then runs your application with an
instance of the Java Virtual Machine.
An overview of the software development process.
http://java.sun.com/docs/white/langenv/http://java.sun.com/docs/white/langenv/http://java.sun.com/docs/books/tutorial/getStarted/intro/definition.html#FOOT%23FOOThttp://java.sun.com/docs/books/tutorial/getStarted/intro/definition.html#FOOT%23FOOThttp://java.sun.com/docs/white/langenv/http://java.sun.com/docs/white/langenv/8/2/2019 Ship A
10/62
Because the Java VM is available on many different operating
systems, the same .class files are capable of running on Microsoft
Windows, the Solaris TM Operating System (Solaris OS), Linux, or Mac
OS. Some virtual machines, such as the Java HotSpot virtual
machine, perform additional steps at runtime to give your application
a performance boost. This include various tasks such as finding
performance bottlenecks and recompiling (to native code) frequently
used sections of code.
Through the Java VM, the same application is
capable of running on multiple platforms.
The Java Platform
A platform is the hardware or software environment in which a
program runs. We've already mentioned some of the most popular
platforms like Microsoft Windows, Linux, Solaris OS, and Mac OS.
http://java.sun.com/products/hotspot/http://java.sun.com/products/hotspot/http://java.sun.com/products/hotspot/http://java.sun.com/products/hotspot/8/2/2019 Ship A
11/62
Most platforms can be described as a combination of the operating
system and underlying hardware. The Java platform differs from most
other platforms in that it's a software-only platform that runs on top
of other hardware-based platforms.
The Java platform has two components:
TheJava Virtual Machine
TheJava Application Programming Interface (API)
You've already been introduced to the Java Virtual Machine; it's the
base for the Java platform and is ported onto various hardware-based
platforms.
The API is a large collection of ready-made software components that
provide many useful capabilities. It is grouped into libraries of related
classes and interfaces; these libraries are known as packages. The
next section, What Can Java Technology Do? highlights some of the
functionality provided by the API.
The API and Java Virtual Machine insulate the
program from the underlying hardware.
http://java.sun.com/docs/books/tutorial/getStarted/intro/cando.htmlhttp://java.sun.com/docs/books/tutorial/getStarted/intro/cando.html8/2/2019 Ship A
12/62
As a platform-independent environment, the Java platform can be a
bit slower than native code. However, advances in compiler and
virtual machine technologies are bringing performance close to that of
native code without threatening portability.
The terms"Java Virtual Machine" and "JVM" mean a Virtual Machine
for the Java platform.
What Can Java Technology Do?
The general-purpose, high-level Java programming language is a
powerful software platform. Every full implementation of the Java
platform gives you the following features:
Development Tools: The development tools provide
everything you'll need for compiling, running, monitoring,
debugging, and documenting your applications. As a new
developer, the main tools you'll be using are the javac compiler,
thejava launcher, and thejavadoc documentation tool.
Application Programming Interface (API): The API
provides the core functionality of the Java programming
language. It offers a wide array of useful classes ready for use
in your own applications. It spans everything from basic
objects, to networking and security, to XML generation and
database access, and more. The core API is very large; to get
8/2/2019 Ship A
13/62
an overview of what it contains, consult the Java SE
Development Kit 6 (JDKTM 6) documentation.
Deployment Technologies: The JDK software provides
standard mechanisms such as the Java Web Start software and
Java Plug-In software for deploying your applications to end
users.
User Interface Toolkits: The Swing and Java 2D toolkits
make it possible to create sophisticated Graphical User
Interfaces (GUIs).
Integration Libraries: Integration libraries such as the Java
IDL API, JDBCTM API, Java Naming and Directory InterfaceTM
("J.N.D.I.") API, Java RMI, and Java Remote Method Invocation
over Internet Inter-ORB Protocol Technology (Java RMI-IIOP
Technology) enable database access and manipulation of
remote objects.
How Will Java Technology Change My Life?
We can't promise you fame, fortune, or even a job if you learn the
Java programming language. Still, it is likely to make your programs
better and requires less effort than other languages. We believe that
Java technology will help you do the following:
Get started quickly: Although the Java programming
language is a powerful object-oriented language, it's easy to
learn, especially for programmers already familiar with C or C+
+.
http://java.sun.com/javase/6/docs/index.htmlhttp://java.sun.com/javase/6/docs/index.htmlhttp://java.sun.com/javase/6/docs/index.htmlhttp://java.sun.com/javase/6/docs/index.htmlhttp://java.sun.com/javase/6/docs/index.htmlhttp://java.sun.com/javase/6/docs/index.html8/2/2019 Ship A
14/62
Write less code: Comparisons of program metrics (class
counts, method counts, and so on) suggest that a program
written in the Java programming language can be four times
smaller than the same program written in C++.
Write better code: The Java programming language
encourages good coding practices, and automatic garbage
collection helps you avoid memory leaks. Its object orientation,
its JavaBeansTM component architecture, and its wide-ranging,
easily extendible API let you reuse existing, tested code and
introduce fewer bugs.
Develop programs more quickly: The Java programming
language is simpler than C++, and as such, your development
time could be up to twice as fast when writing in it. Your
programs will also require fewer lines of code.
Avoid platform dependencies: You can keep your program
portable by avoiding the use of libraries written in other
languages.
Write once, run anywhere: Because applications written in
the Java programming language are compiled into machine-
independent bytecodes, they run consistently on any Java
platform.
Distribute software more easily: With Java Web Start
software, users will be able to launch your applications with a
single click of the mouse. An automatic version check at startup
ensures that users are always up to date with the latest version
8/2/2019 Ship A
15/62
of your software. If an update is available, the Java Web Start
software will automatically update their installation.
8/2/2019 Ship A
16/62
SOFTWAREAND
HARDWARE REQUIRMENTS
8/2/2019 Ship A
17/62
SOFTWARE & HARDWARE REQUIREMENTS
SOFTWARE REQUIREMENTS
1. Java SDK1.3
2. Ms Office
Minimum HARDWARE REQUIREMENTS
1. Computer P-3
2. RAM 256 MB
3. WINDOWS 98 SE
4. HARDISK (40 GB)
8/2/2019 Ship A
18/62
SOURCE CODE OF THE PROJECT
8/2/2019 Ship A
19/62
SHILPA RANI
MANDEEP
KAUR
RAMANDEEP
KAUR
8/2/2019 Ship A
20/62
SOURCE CODE OF THE CALCULATOR
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.applet.*;
import java.math.*;
import java.io.*;
import java.lang.*;
public class MyCalc extends Applet implements
ActionListener,ItemListener,KeyListener
{
private MyFile f=new MyFile();//class MyFile is an inner
class contains the methods we used to act with the files
private CheckboxGroup deg;
private TextArea ta;
private Label l,memoryTag;
private MyButton[] button;
private TextField t;
private String s="0",s1="",s2="",op="",s3="";
private double m=0,n=0,mem=0;
8/2/2019 Ship A
21/62
private Panel p1,p2,p3,p4,p5,p6,p7,p8;
private String[]
Sbutton={"Power","Advanced","Shift","C","CE","Back
Space","7","8","9","4",
"5","6","1","2","3","0",".","PI","=","Ans"
,"Sin","Cos","Sqrt","Sqr","X!","Pow","%",
"1/X","+/-","S_Store",
"E_Store","/","Del","*","Me","-","M+","+
","M-","MR",
"R","Previow","Close"};
private boolean
cond=false,cond1=false,cond2=false,cond3=false,cond4=false,c
ond5=true,pressed=false;
/*
the conditions :
1:cond :for advanced button
2:cond1 :for Power
3:cond3 :for checkbox radian or degrees
4:cond4 :for start saving and end saving into the file
5:cond5 :for the simecolon
5:pressed for making the textfield = "" after any
calculation
8/2/2019 Ship A
22/62
*/
public void init()
{
setLayout(new BorderLayout(0,7));//the layout for
the applet
setBackground(new Color(58,110,165));
l=new Label(" Bad Info Guys");
memoryTag=new Label(" ");
memoryTag.setEnabled(true);
l.setFont(new Font("Times Roman",Font.BOLD,17));
memoryTag.setFont(new Font("Times
Roman",Font.BOLD,17));
memoryTag.setForeground(Color.black);
l.setForeground(Color.green);
l.setForeground(Color.green);
ta=new TextArea("Bahaa
Mourad\nGoergeElias\nSamer Al_Fakih\nBashar
Mahasin\n-----------------------\n",8,17,TextArea.SCROLLBARS_
VERTICAL_ONLY);
ta.setFont(new Font("Times Roman",Font.BOLD,12));
ta.setEditable(false);
8/2/2019 Ship A
23/62
deg = new CheckboxGroup();//the container of the
checkboxs
Checkbox degrees = new Checkbox("Deg",deg,true);
Checkbox radians = new Checkbox("Rad",deg,false);
button =new MyButton[43];
for(int i=0;i
8/2/2019 Ship A
24/62
p5=new Panel();
p6=new Panel();
p7=new Panel();
p8=new Panel();
//adding the components to matching panel
p5.setBounds(20,1,275,30);
p5.add(button[0]);
p5.add(l);
add(p5);
p1.setLayout(new GridLayout(3,3,2,2));
p1.setBounds(20,104,225,78);
for(int i=20;i
8/2/2019 Ship A
25/62
p4.add(button[2]);
p4.add(degrees);
p4.add(radians);
t.setBackground(Color.black);
add(p2);
p3.setLayout(new GridLayout(6,3,2,3));
p3.setBounds(20,190,225,156);
for (int i=3;i
8/2/2019 Ship A
26/62
t=new TextField(30);
t.setFont(new Font("Times Roman",Font.BOLD,12));
t.addKeyListener(this);
t.setText("0");
//constructin the panels in the applet
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
p5=new Panel();
p6=new Panel();
p7=new Panel();
p8=new Panel();
//adding the components to matching panel
p5.setBounds(20,1,275,30);
p5.add(button[0]);
p5.add(l);
add(p5);
p1.setLayout(new GridLayout(3,3,2,2));
p1.setBounds(20,104,225,78);
8/2/2019 Ship A
27/62
for(int i=20;i
8/2/2019 Ship A
28/62
p7.setBounds(300,1,150,182);
p7.add(ta);
p7.add(button[41]);
p7.add(button[42]);
add(p7);
p6.setLayout(new GridLayout(6,2,2,2));
p6.setBounds(300,190,150,156);
p8.setBounds(0,0,400,40);
for(int i=29;i
8/2/2019 Ship A
29/62
t.setEditable(false);
//adding the action listener
for(int i=0;i
8/2/2019 Ship A
30/62
op="";
}
else if (op.compareTo("-")==0)
{
l=m-n;
op="";
}
else if (op.compareTo("*")==0)
{
l=m*n;
op="";
}
else if (op.compareTo("/")==0)
{
l=m/n;
op="";
}
else if (op.compareTo("")==0)
{
l=Double.valueOf(s2).doubleValue();
}
8/2/2019 Ship A
31/62
else if (op.compareTo("Pow")==0)
{
o=Integer.valueOf(s2).intValue();
l=MyMath.mypow(m,o);
op="";
}
cond5=true;
pressed=true;
s=""+l;
t.setText(s);
f.addTofile(s1+opp+s2+"="+l);
}
public void keyPressed(KeyEvent e)
{
double ac=e.getKeyCode();
if((ac==13)||(ac==10))
calculate();
else if(ac==8)
8/2/2019 Ship A
32/62
{
if(s.compareTo("")==0)
t.setText("Error");
else
{
s=s.substring(0,s.length()-1);
t.setText(s);
}
}
}
public void keyTyped(KeyEvent e)
{
char ch;
ch=e.getKeyChar();
if ((ch=='1')||(ch=='2')||(ch=='3')||(ch=='4')||
(ch=='5')||(ch=='6')||(ch=='7')||(ch=='8')||(ch=='9')||
(ch=='0'))
{ if(pressed)
{
s="0";
pressed=false;
}
if(s=="0")
8/2/2019 Ship A
33/62
s=""+ch;
else s=s+ch;
}
else if(ch=='.'&&cond5)
{
if(pressed)
{
s="0";
pressed=false;
}
s=s+ch;
cond5=false;
}
else if((ch=='+')||(ch=='-')||(ch=='*')||(ch=='/'))
{
op=""+ch;
s1=s;
s="0";
}
else if(ch=='=')
calculate();
t.setText(s);
8/2/2019 Ship A
34/62
}
public void keyReleased(KeyEvent e)
{
}
public void itemStateChanged(ItemEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==button[29])//for begin store in
the file
{
cond4=true;
button[30].setEnabled(true);
button[29].setEnabled(false);
f.CreateFile();
}
else if (e.getSource()==button[30])//end of the
storing
{
cond4=false;
button[29].setEnabled(true);
8/2/2019 Ship A
35/62
button[30].setEnabled(false);
f.endStore();
}
else if (e.getSource()==button[41])//preview
{
button[41].setEnabled(false);
button[42].setEnabled(true);
f.WriteFileOnTextArea();
}
else if (e.getSource()==button[42])//close for
textarea
{
button[41].setEnabled(true);
button[42].setEnabled(false);
ta.setText("Bahaa
Mourad\nGoergeElias\nSamer Al_Fakih\nBashar
Mahasin\n-----------------------\n");
}
else if (e.getSource()==button[32])//Del button
{
f.CreateFile();
}
8/2/2019 Ship A
36/62
else if (e.getSource()==button[1])//for advanced
buttons
{
if(!cond)
{
cond=true;
p1.setVisible(true);
button[1].setLabel("Simple");
for(int i=20;i
8/2/2019 Ship A
37/62
t.setBackground(Color.white);
cond1=true;
button[0].setLabel("OFF");
for(int i=1;i
8/2/2019 Ship A
38/62
button[i].setEnabled(false);
}
}
else if(e.getSource()==button[16])//semicolon
{
if(pressed)
{
s="0";
pressed=false;
}
if (cond5)
{
s=s+".";
cond5=false;
t.setText(s);
}
}
//The implemetation of the Number Buttons
else if ((e.getSource()==button[6]) ||
(e.getSource()==button[7]) || (e.getSource()==button[8]) ||
(e.getSource()==button[9]) || (e.getSource()==button[10]) ||
(e.getSource()==button[11]) || (e.getSource()==button[12]) ||
8/2/2019 Ship A
39/62
(e.getSource()==button[13]) || (e.getSource()==button[14]) ||
(e.getSource()==button[15]) )
{ if(pressed)
{
s="0";
pressed=false;
}
if(s.compareTo("0")==0)
s=e.getActionCommand();
else s=s+e.getActionCommand();
s3=s;
t.setText(s);
showStatus(e.getActionCommand());
}
//the opertor section (simple opertaion)
else if ((e.getSource()==button[37])||
(e.getSource()==button[35])||(e.getSource()==button[33])||
(e.getSource()==button[31])||(e.getSource()==button[25]))
{
cond5=true;
op=e.getActionCommand();
s1=s;
8/2/2019 Ship A
40/62
s3=s;
s="0";
t.setText(s);
}
else if ((e.getSource()==button[18]))
calculate();
else if (e.getSource()==button[5])
{
s=s.substring(0,s.length()-1);
t.setText(s);
}
else if (e.getSource()==button[3])
{
op="";
s=s3;
t.setText(s);
}
else if (e.getSource()==button[4])
{
t.setText("0");
cond5=true;
s="0";
s1="";
8/2/2019 Ship A
41/62
s2="";
}
else if (e.getSource()==button[27])
{
pressed=true;
float g=0,p=0;
p=Float.valueOf(s).floatValue();
if(p==0)
{
s="0";
t.setText("Invinite");
}
else{
g=(1/p);
s=""+g;
s3=s;
t.setText(s);
f.addTofile("1/"+p+"="+s);
}
}
else if (e.getSource()==button[28])
{
if (!(s.compareTo("0")==0))
8/2/2019 Ship A
42/62
{
if(s.charAt(0)=='-')
s=s.substring(1,s.length());
else
s="-"+s;
t.setText(s);
}
}
else if(e.getSource()==button[34])
{
pressed=true;
memoryTag.setText("M");
mem=Double.valueOf(s).doubleValue();
if(mem==0)
memoryTag.setText(" ");
showStatus("Memory="+mem);
}
else if(e.getSource()==button[36])
{
pressed=true;
memoryTag.setText("M");
mem=mem+
(Double.valueOf(s).doubleValue());
8/2/2019 Ship A
43/62
if(mem==0)
memoryTag.setText(" ");
showStatus("Memory="+mem);
}
else if(e.getSource()==button[38])
{
pressed=true;
memoryTag.setText("M");
mem=mem-(Double.valueOf(s).doubleValue());
if(mem==0)
memoryTag.setText(" ");
showStatus("Memory="+mem);
}
else if(e.getSource()==button[39])
{
s=""+mem;
s3=s;
t.setText(s3);
}
else if(e.getSource()==button[20])
{
pressed=true;
8/2/2019 Ship A
44/62
double x=Double.valueOf(s).doubleValue();
String s4 =
deg.getSelectedCheckbox().getLabel();
if (!cond3)
{
if(s4.equals("Deg"))
{
while(x>=360)
x=x-360;
s=""+MyMath.msin(MyMath.invert(x));
t.setText(""+s);
}
else if(s4.equals("Rad"))
{
while(x>=(2*Math.PI))
x=x-Math.PI;
s=""+MyMath.msin(x);
t.setText(s);
}
f.addTofile("Sin("+x+")="+s);
}
else
8/2/2019 Ship A
45/62
{
if(s4.equals("Deg"))
{
x=Double.valueOf(s).doubleValue();
s=""+MyMath.invertt(Math.asin(x));
t.setText(""+s);
}
else if(s4.equals("Rad"))
{
x=Double.valueOf(s).doubleValue();
s=""+MyMath.invertt(Math.acos(x));
t.setText(s);
}
s3=s;
f.addTofile("aSin("+x+")="+s);
}
}
else if(e.getSource()==button[21])
{
pressed=true;
double x=Double.valueOf(s).doubleValue();
String s4 =
deg.getSelectedCheckbox().getLabel();
8/2/2019 Ship A
46/62
if (!cond3)
{
if(s4.equals("Deg"))
{
while (x>=360)
x=x-360;
s=""+MyMath.mcos(MyMath.invert(x));
t.setText(s);
s3=s;
}
else if(s4.equals("Rad"))
{
while(x>=(2*Math.PI))
x=x-Math.PI;
s=""+MyMath.mcos(x);
t.setText(s);
s3=s;
}
f.addTofile("Cos("+x+")="+s);
}
else
{
8/2/2019 Ship A
47/62
if(s4.equals("Deg"))
{
x=Double.valueOf(s).doubleValue();
s=""+MyMath.invertt(Math.acos(x));
t.setText(s);
s3=s;
}
else if(s4.equals("Rad"))
{
x=Double.valueOf(s).doubleValue();
s=""+MyMath.invertt(Math.acos(x));
t.setText(s);
s3=s;
}
f.addTofile("aCos("+x+")="+s);
}
}
else if(e.getSource()==button[23])
8/2/2019 Ship A
48/62
{
pressed=true;
double y=0;
double
x=Double.valueOf(s).doubleValue();
y=MyMath.mysqr(x);
t.setText(""+y);
s=""+y;
s3=s;
f.addTofile("sqr("+x+")="+s);
}
else if(e.getSource()==button[24])
{
pressed=true;
int x=Integer.valueOf(s).intValue();
if(x>39)
t.setText("Invinit");
else
{
s=""+MyMath.myX(x);
t.setText(""+s);
s3=s;
8/2/2019 Ship A
49/62
f.addTofile(""+x+"!="+s);
}
}
else if(e.getSource()==button[2])
{
if(!cond3)
{
button[20].setLabel("arcSin");
button[21].setLabel("arcCos");
cond3=true;
}
else
{
cond3=false;
button[20].setLabel("Sin");
button[21].setLabel("Cos");
}
}
else if(e.getSource()==button[40])
{
t.setText("0");
mem=0;
8/2/2019 Ship A
50/62
memoryTag.setText("");
}
else if(e.getSource()==button[26])
{
pressed=true;
float p,r;
p=Float.valueOf(s).floatValue();
r=p/100;
s=""+r;
s3=s;
t.setText(s);
f.addTofile(""+p+"%="+s);
}
else if(e.getSource()==button[22])
{
pressed=true;
double l=0;
m=Double.valueOf(s).doubleValue();
l=Math.sqrt(m);
s=""+l;
s3=s;
t.setText(s);
8/2/2019 Ship A
51/62
f.addTofile("sqrt("+m+")="+s);
}
else if (e.getSource()==button[19])
{
pressed=true;
t.setText(s3);
s=s3;
showStatus(s3);
}
else if (e.getSource()==button[17])
{
pressed=true;
t.setText(""+3.1415926);
s=""+3.1415926;
}
}
public static void main(String args[])
{
Frame app=new Frame("Calculator");
8/2/2019 Ship A
52/62
app.setSize(470,400);
app.addWindowListener(new
CloseWindowAndExit());
MyCalc m=new MyCalc();
m.init();
m.start();
app.add(m,BorderLayout.CENTER);
app.setVisible(true);
}
class MyButton extends Button
{
public MyButton(String name,Color xyz)
{
//here we override the constructor of the button
//first we call the Main constructor and then
//we add the color proprty and response for mouse motion
super(name);
setBackground(xyz);
addMouseListener(new MouseCalcButtonAdapter());
}
class MouseCalcButtonAdapter extends MouseAdapter
{
8/2/2019 Ship A
53/62
Color color;
public void mouseEntered(MouseEvent me)
{
color=me.getComponent().getBackground();
setForeground(Color.red);
setBackground(Color.black);
setFont(new Font("Courier
New",Font.BOLD,12));
}
public void mouseExited(MouseEvent me)
{
setFont(new Font("Courier
New",Font.BOLD,10));
setForeground(Color.black);
me.getComponent().setBackground(color);
}
}
}
class MyFile //MyFile is inner class
{
8/2/2019 Ship A
54/62
private DataOutputStream Of;
public void WriteFileOnTextArea()
{
String str;
char st;
str="";
try
{
DataInputStream If=new DataInputStream(new
FileInputStream("FileOutput.txt"));
while(If.readLine()!=null)
{
if ((st=If.readChar())!='E')
{
str=st+str;
}
if (st=='E')
{
ta.append(str);
ta.append("\n");
str="";
}
}
8/2/2019 Ship A
55/62
If.close();
}
catch(FileNotFoundException e) {}
catch(IOException e) {}
}
public void CreateFile()
{
try
{
Of=new DataOutputStream(new
FileOutputStream("FileOutput.txt"));
Of.writeChars("Begin\n");
}
catch(IOException e) {
System.err.println("File not opened
properly\n"+e.toString());
System.exit(1);
}
}
public void addTofile(String str)
{
try
8/2/2019 Ship A
56/62
{
for(int i=str.length()-1;i>=0;i--)
{
Of.writeChar(str.charAt(i));
Of.writeChars("\n");
}
Of.writeChar('E');
Of.writeChars("\n");
}
catch (IOException io){}
}
public void delFile()
{
CreateFile();
try
{
Of.close();
}
catch (IOException io){}
}
public void endStore()
{
try
8/2/2019 Ship A
57/62
{
Of.close();
}
catch (IOException io){}
}
}
}
class MyMath
{
public static double msin(double x)
{
if (x
8/2/2019 Ship A
58/62
if (x
8/2/2019 Ship A
59/62
double s;
s=1;
for(int i=1;i0;i--)
t=i*t;
return t;
}
}
8/2/2019 Ship A
60/62
class CloseWindowAndExit implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
};
8/2/2019 Ship A
61/62
BIBLIOGRAPHY
8/2/2019 Ship A
62/62
BIBLIOGRAPHY
For Making Project We Use Some Book For Coding And Use Some
Reference Notes Provided By Our Guide To Complete This Project
1. Java In 21 Days Bpb Publication
2. Applet Programming In Java
3. Java Complete Reference
4. Java In Easy Step By Dreamtech Publication