Anda di halaman 1dari 62

ON

ADVANCE 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

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

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)

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)

INDEX
1. 2. 3. 4. 5. 6. 7. 8. Certificate Preface Acknowledgment hardware and software requirements introduction to project introduction to java source code of the project bibliography

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 .

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

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.

The Java Programming Language The Java programming language is a high-level language that can be characterized by all of the following buzzwords: Simple Object oriented Distributed Multithreaded Dynamic Architecture neutral Portable High performance Robust 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 the javac 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). The java launcher tool then runs your application with an instance of the Java Virtual Machine.

An overview of the software development process.

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.

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: The Java Virtual Machine The Java 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.

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, the java launcher, and the javadoc 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

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+ +.

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 machineindependent 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

of your software. If an update is available, the Java Web Start software will automatically update their installation.

SOFTWARE AND HARDWARE REQUIRMENTS

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)

SOURCE CODE OF THE PROJECT

SHILPA RANI MANDEEP KAUR RAMANDEEP KAUR

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;

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

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

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<20;i++)//creating the Advanced buttons like sin & cos & arcsin etc.. button[i]=new MyButton(Sbutton[i],new Color(174,168,217)); for(int i=20;i<43;i++)//creating the numbers button[i]=new MyButton(Sbutton[i],new Color(58,222,160));

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); for(int i=20;i<29;i++) p1.add(button[i]); p1.setVisible(false); add(p1);

p2.setBounds(20,32,280,70); p2.add(t); p2.add(memoryTag); p2.add(p4); p4.add(button[1]);

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<20;i++) p3.add(button[i]); add(p3);

p7.setBounds(300,1,150,182); p7.add(ta); p7.add(button[41]); p7.add(button[42]); add(p7); button[i]=new MyButton(Sbutton[i],new Color(174,168,217)); for(int i=20;i<43;i++)//creating the numbers button[i]=new MyButton(Sbutton[i],new Color(58,222,160));

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

for(int i=20;i<29;i++) p1.add(button[i]); p1.setVisible(false); add(p1);

p2.setBounds(20,32,280,70); p2.add(t); p2.add(memoryTag); p2.add(p4); p4.add(button[1]); 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<20;i++) p3.add(button[i]); add(p3);

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<41;i++) p6.add(button[i]);

add(p6);

add(p8); //befor you can use the Calculator you have to press the power for(int i=1;i<43;i++) button[i].setEnabled(false);

t.setEditable(false); //adding the action listener for(int i=0;i<43;i++) button[i].addActionListener(this); degrees.addItemListener(this); radians.addItemListener(this);

} //this procedure compute the calculation needed public void calculate() { double l=0; int o=0; String opp=""; s2=s; s="0"; m=Double.valueOf(s1).doubleValue(); n=Double.valueOf(s2).doubleValue(); opp=op;

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=m/n; op=""; } else if (op.compareTo("")==0) {

l=Double.valueOf(s2).doubleValue(); }

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)

{ 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")

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

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

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

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<29;i++) button[i].setEnabled(true); } else { button[1].setLabel("Advanced"); p1.setVisible(false); cond=false; } } else if (e.getSource()==button[0])//power { if(!cond1) { cond5=true;

t.setBackground(Color.white); cond1=true; button[0].setLabel("OFF"); for(int i=1;i<42;i++) button[i].setEnabled(true); button[30].setEnabled(false); } else { cond1=false; cond5=true; pressed=false; t.setBackground(Color.black); ta=new TextArea("Bahaa Mourad\nGoergeElias\nSamer Al_Fakih\nBashar Mahasin\n-----------------------\n"); f.delFile(); s="0";s1="";s2=""; memoryTag.setText(" "); t.setText(s); mem=0; button[0].setLabel("ON"); for(int i=1;i<43;i++)

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

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

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="";

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

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

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;

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

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

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 {

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

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

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;

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

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

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 {

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

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=""; } }

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

{ 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

{ Of.close(); } catch (IOException io){} }

class MyMath

{ public static double msin(double x) { if (x<=0.0005) x=x+((x*x*x)/6); else x=2*msin(x/2)*mcos(x/2); return x; } public static double mcos(double x) {

if (x<=0.0005) x=1-((x*x*x)/2); else x=(mcos(x/2)*mcos(x/2))-(msin(x/2)*msin(x/2)); return x; } public static double invertt(double x) { //converting from radian to degree double y; y=(180*x)/Math.PI; return y; }

public static double invert(double x) { //converting from degree to radian double y; y=(Math.PI*x)/180; return y; } public static double mypow(double x,int y) {

double s; s=1; for(int i=1;i<=y;i++) s=s*x; return s; }

public static double mysqr(double x) { double s=x*x; return s; }

public static long myX(int x) //factorial function { long t=1; for(int i=x;i>0;i--) t=i*t; return t; }

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

BIBLIOGRAPHY

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

Anda mungkin juga menyukai