dcsimg
I have a problem in building calculator please help me i have commented where is the problem
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Fayyaz_Ali
Posted On:   Monday, October 18, 2004 12:59 PM

please some one show me how to code for the +,-,/,*,= buttons. Below is my Code Please Correct IT. /* * Main.java * * Created on October 7, 2004, 5:42 PM */ // Declaring the package Calculator /** * * @author Anees Bhai */ // importing awt (Abstract Windowing Toolkit) classes package Calculator; import java.awt.*; // importing the image classes import java.awt.Image.*; // importing the color classes import java.awt.Color.*; // importing the event classes import java.awt.event.*; // importing the Math classes import java.math.*; // importing the input output classe   More>>

please some one show me how to code for the +,-,/,*,= buttons. Below is my Code Please Correct IT.

			
/*
* Main.java
*
* Created on October 7, 2004, 5:42 PM
*/
// Declaring the package Calculator

/**
*
* @author Anees Bhai
*/

// importing awt (Abstract Windowing Toolkit) classes
package Calculator;

import java.awt.*;
// importing the image classes
import java.awt.Image.*;
// importing the color classes
import java.awt.Color.*;
// importing the event classes
import java.awt.event.*;
// importing the Math classes
import java.math.*;
// importing the input output classes
import java.io.*;
// Declaring the class which inherits from the class Frame and
// Interface ActionListener.
public class Main extends Frame implements ActionListener{
// Declaring the GridBagLayout and GridbagConstraints
GridBagLayout gb;
GridBagConstraints gbc;
// Declaring a TextField
TextField tf1;
// Declaring Multiple Buttons in a Single Statement

Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0,bexit,bBack,bPlus,
bMinus,bMultiply,bDivide,bModulus,bEqual,bC,bPlusMinus,bDot,boneorx,bSqrt
,bClearMem,bMemCall,bMemSave,bMemS,bPi,bsqr,bCube,bTan,bSin,bCos,bLog
,bnl,bRnd,bDeg,bRad,bDec,bOct,bHex,bBin,bExp,bEmc,bRan,bc,bh,bG,
be,bme,bu,bNA,bk,bVm;
// Declaring a Label
Label filler;

// Declaring and Initializing a new Color
Color newco=new Color(204,204,204);

String Mem=new String();
double add,subtract,div,multiply,ans;

/** Creates a new instance of Main */
public Main(String title) {
super(title);
// Initializing the buttons,textfield and other components
bexit=new Button("Exit");
b1=new Button(" 1 ");
b2=new Button(" 2 ");
b3=new Button(" 3 ");
b4=new Button(" 4 ");
b5=new Button(" 5 ");
b6=new Button(" 6 ");
b7=new Button(" 7 ");
b8=new Button(" 8 ");
b9=new Button(" 9 ");
b0=new Button(" 0 ");
bBack=new Button(" Back ");
bPlus=new Button(" + ");
bMinus=new Button(" - ");
bMultiply=new Button(" * ");
bDivide=new Button(" / ");
bModulus=new Button(" % ");
bEqual=new Button(" = ");
bPlusMinus=new Button(" +/- ");
bC=new Button(" C ");
bDot=new Button(" . ");
boneorx=new Button(" 1/X ");
bSqrt=new Button(" Sqrt ");
bClearMem=new Button(" MC ");
bMemCall=new Button(" MR ");
bMemSave=new Button(" M+ ");
bMemS=new Button(" MS ");
bPi=new Button(" Pi ");
bsqr=new Button(" X^2 ");
bCube=new Button(" X^3 ");
bTan=new Button(" tan ");
bCos=new Button(" cos ");
bSin=new Button(" sin ");
bLog=new Button(" log ");
bnl=new Button(" nl ");
bRnd=new Button(" Round ");
bDeg=new Button(" Degrees ");
bRad=new Button(" Radians ");
bHex=new Button(" Hex ");
bDec=new Button(" Decimal ");
bOct=new Button(" Octal ");
bBin=new Button(" Binary ");
bExp=new Button(" Exp ");
bEmc=new Button( " E=mc^2 " );
bc=new Button(" c ");
bh=new Button(" h ");
bG=new Button(" G ");
be=new Button(" e ");
bme=new Button(" me ");
bu=new Button(" u ");
bNA=new Button(" NA ");
bk=new Button(" k ");
bVm=new Button(" Vm ");
filler=new Label("");
tf1=new TextField(60);
// Setting Layout Manager for the Components
gb=new GridBagLayout();
gbc=new GridBagConstraints();
setLayout(gb);
this.setBackground(newco);
// adding different Components to the Frame(Container)
addComponent(tf1,0,0,11,1);
addComponent(filler,1,0,4,1);
gbc.fill=GridBagConstraints.HORIZONTAL;
addComponent(b7,2,0,1,1);
addComponent(b4,3,0,1,1);
addComponent(b1,4,0,1,1);
addComponent(b0,5,0,1,1);
addComponent(bBack,6,0,1,1);
addComponent(b8,2,1,1,1);
addComponent(b5,3,1,1,1);
addComponent(b2,4,1,1,1);
addComponent(bPlusMinus,5,1,1,1);
addComponent(bC,6,1,1,1);
addComponent(b9,2,2,1,1);
addComponent(b6,3,2,1,1);
addComponent(b3,4,2,1,1);
addComponent(bDot,5,2,1,1);
addComponent(bDeg,6,2,2,1);
addComponent(bDivide,2,3,1,1);
addComponent(bMultiply,3,3,1,1);
addComponent(bMinus,4,3,1,1);
addComponent(bPlus,5,3,1,1);
addComponent(bSqrt,2,4,1,1);
addComponent(bEmc,3,4,1,1);
addComponent(boneorx,4,4,1,1);
addComponent(bEqual,5,4,1,1);
addComponent(bRad,6,4,2,1);
addComponent(bClearMem,2,5,1,1);
addComponent(bMemCall,3,5,1,1);
addComponent(bMemS,4,5,1,1);
addComponent(bMemSave,5,5,1,1);
addComponent(bPi,2,6,1,1);
addComponent(bsqr,3,6,1,1);
addComponent(bCube,4,6,1,1);
addComponent(bLog,5,6,1,1);
addComponent(bnl,6,6,1,1);
addComponent(bCos,2,7,1,1);
addComponent(bSin,3,7,1,1);
addComponent(bTan,4,7,1,1);
addComponent(bExp,5,7,1,1);
addComponent(bexit,6,7,1,1);
addComponent(bHex,2,8,2,1);
addComponent(bDec,3,8,2,1);
addComponent(bOct,4,8,2,1);
addComponent(bBin,5,8,2,1);
addComponent(bRnd,6,8,2,1);
addComponent(bc,2,10,1,1);
addComponent(bh,3,10,1,1);
addComponent(bG,4,10,1,1);
addComponent(be,5,10,1,1);
addComponent(bme,6,10,1,1);
addComponent(bu,2,11,1,1);
addComponent(bNA,3,11,1,1);
addComponent(bk,4,11,1,1);
addComponent(bVm,5,11,1,1);

// Set the Font Color for the Buttons
bMultiply.setForeground(Color.red);
bMinus.setForeground(Color.red);
bPlus.setForeground(Color.red);
bEqual.setForeground(Color.red);
bClearMem.setForeground(Color.red);
bMemCall.setForeground(Color.red);
bMemS.setForeground(Color.red);
bMemSave.setForeground(Color.red);
bDivide.setForeground(Color.red);
bBack.setForeground(Color.red);
bC.setForeground(Color.red);
bexit.setForeground(Color.orange);
b1.setForeground(Color.blue);
b2.setForeground(Color.blue);
b3.setForeground(Color.blue);
b4.setForeground(Color.blue);
b5.setForeground(Color.blue);
b6.setForeground(Color.blue);
b7.setForeground(Color.blue);
b8.setForeground(Color.blue);
b9.setForeground(Color.blue);
b0.setForeground(Color.blue);
bPlusMinus.setForeground(Color.blue);
bDot.setForeground(Color.blue);
bSqrt.setForeground(Color.blue);
boneorx.setForeground(Color.blue);
bPi.setForeground(Color.blue);
bsqr.setForeground(Color.blue);
bTan.setForeground(Color.blue);
bCos.setForeground(Color.blue);
bSin.setForeground(Color.blue);
bLog.setForeground(Color.blue);
bnl.setForeground(Color.blue);
bCube.setForeground(Color.blue);
bRnd.setForeground(Color.blue);
bDeg.setForeground(Color.blue);
bRad.setForeground(Color.blue);
bHex.setForeground(Color.blue);
bDec.setForeground(Color.blue);
bOct.setForeground(Color.blue);
bBin.setForeground(Color.blue);
bExp.setForeground(Color.blue);
bEmc.setForeground(Color.blue);
bc.setForeground(Color.blue);
bh.setForeground(Color.blue);
bG.setForeground(Color.blue);
be.setForeground(Color.blue);
bme.setForeground(Color.blue);
bk.setForeground(Color.blue);
bNA.setForeground(Color.blue);
bVm.setForeground(Color.blue);
bu.setForeground(Color.blue);

//Setting the BackGround Color for the Buttons
b0.setBackground(newco);
b1.setBackground(newco);
b2.setBackground(newco);
b3.setBackground(newco);
b4.setBackground(newco);
b5.setBackground(newco);
b6.setBackground(newco);
b7.setBackground(newco);
b8.setBackground(newco);
b9.setBackground(newco);
b0.setBackground(newco);
bC.setBackground(newco);
bBack.setBackground(newco);
boneorx.setBackground(newco);
bSqrt.setBackground(newco);
bexit.setBackground(newco);
bMinus.setBackground(newco);
bPlus.setBackground(newco);
bDot.setBackground(newco);
bDivide.setBackground(newco);
bMultiply.setBackground(newco);
bMemCall.setBackground(newco);
bMemS.setBackground(newco);
bMemSave.setBackground(newco);
bClearMem.setBackground(newco);
bPlusMinus.setBackground(newco);
bEqual.setBackground(newco);
bsqr.setBackground(newco);
bTan.setBackground(newco);
bSin.setBackground(newco);
bCos.setBackground(newco);
bCube.setBackground(newco);
bPi.setBackground(newco);
bLog.setBackground(newco);
bnl.setBackground(newco);
bRnd.setBackground(newco);
bDeg.setBackground(newco);
bRad.setBackground(newco);
bHex.setBackground(newco);
bDec.setBackground(newco);
bOct.setBackground(newco);
bBin.setBackground(newco);
bExp.setBackground(newco);
bEmc.setBackground(newco);
bc.setBackground(newco);
bh.setBackground(newco);
bG.setBackground(newco);
bk.setBackground(newco);
be.setBackground(newco);
bme.setBackground(newco);
bu.setBackground(newco);
bVm.setBackground(newco);
bNA.setBackground(newco);

// Adding ActionListener to the Buttons
bexit.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
bC.addActionListener(this);
bDot.addActionListener(this);
boneorx.addActionListener(this);
bEqual.addActionListener(this);
bMultiply.addActionListener(this);
bMinus.addActionListener(this);
bPlusMinus.addActionListener(this);
bPlus.addActionListener(this);
bEmc.addActionListener(this);
bMemCall.addActionListener(this);
bMemS.addActionListener(this);
bMemSave.addActionListener(this);
bClearMem.addActionListener(this);
bSqrt.addActionListener(this);
bBack.addActionListener(this);
bDivide.addActionListener(this);
bsqr.addActionListener(this);
bPi.addActionListener(this);
bCube.addActionListener(this);
bCos.addActionListener(this);
bSin.addActionListener(this);
bTan.addActionListener(this);
bLog.addActionListener(this);
bnl.addActionListener(this);
bRnd.addActionListener(this);
bDeg.addActionListener(this);
bRad.addActionListener(this);
bExp.addActionListener(this);
bHex.addActionListener(this);
bOct.addActionListener(this);
bDec.addActionListener(this);
bBin.addActionListener(this);
bc.addActionListener(this);
bh.addActionListener(this);
bG.addActionListener(this);
be.addActionListener(this);
bme.addActionListener(this);
bk.addActionListener(this);
bu.addActionListener(this);
bVm.addActionListener(this);
bNA.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
String a=tf1.getText();
// Checking that the button is clicked or not
if (ae.getSource()==bexit){
// If the Button is Clicked then take the Actions Below;
// System.exit is used to close or terminate a programme
// where Zero Means Normal termination.
System.exit(0);
}
if (ae.getSource()==b1){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("1");
}
else{
tf1.setText(a+"1");
}
}
if (ae.getSource()==b2){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("2");
}
else{
tf1.setText(a+"2");
}
}
if (ae.getSource()==b3){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("3");
}
else{
tf1.setText(a+"3");
}
}
if (ae.getSource()==b4){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("4");
}
else{
tf1.setText(a+"4");
}
}
if (ae.getSource()==b5){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("5");
}
else{
tf1.setText(a+"5");
}
}
if (ae.getSource()==b6){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("6");
}
else{
tf1.setText(a+"6");
}
}
if (ae.getSource()==b7){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("7");
}
else{
tf1.setText(a+"7");
}
}
if (ae.getSource()==b8){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("8");
}
else{
tf1.setText(a+"8");
}
}
if (ae.getSource()==b9){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("9");
}
else{
tf1.setText(a+"9");
}
}
if (ae.getSource()==b0){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("0");
}
else{
tf1.setText(a+"0");
}
}
if (ae.getSource()==bC){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("");
}
else{
tf1.setText("");
}
}
if (ae.getSource()==bDot){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("0.");
}
else{
tf1.setText(a+".0");
}
}
if(ae.getSource()==bBack){
if (a.equals("")|(a==null)|(a=="0")){
tf1.setText("");
}
else{
// get the text of the textfield which is "a"
// change it to stringbuffer which is "s"
// subtract 1 from the length of the string
// the last number will be removed from the string

StringBuffer s=new StringBuffer(a);
s.setLength(a.length()-1);
tf1.setText(s.toString());
}
}
if(ae.getSource()==bMultiply){
//Here is the problem
try{
double d=Double.valueOf(a.trim()).doubleValue();
multiply=d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException: "+nfe.getMessage());
}
tf1.setText("");
}
if(ae.getSource()==bDivide){
//Here is the problem
try{
double d=Double.valueOf(a.trim()).doubleValue();
div=d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException: "+nfe.getMessage());
}
tf1.setText("");
}
if(ae.getSource()==bPlus){
//Here is the problem
try{
double d=Double.valueOf(a.trim()).doubleValue();
add=d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException: "+nfe.getMessage());
}
tf1.setText("");
}
if(ae.getSource()==bPlusMinus){
// For Changing the sign of the number we multiplied it by -1
// if it is positive number then it will become negative number
// if it is negative number then it will become positive.
double value=0;
String result;
try{
double d = Double.valueOf(a.trim()).doubleValue();
value = d*-1;
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
result = String.valueOf(value);
tf1.setText(result);
}
if(ae.getSource()==bMinus){
//HEre is the problem
try{
double d=Double.valueOf(a.trim()).doubleValue();
subtract=d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException: "+nfe.getMessage());
}
tf1.setText("");
}
// Find the square root of a number
if(ae.getSource()==bSqrt){
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
num = Math.sqrt(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
if(ae.getSource()==bEmc){
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// 3E8 Is the speed of Light and d is the mass of the object
// we have E=mc^2
num = d*3E8*3E8;
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
if(ae.getSource()==bEqual){
//HERE is the Problem
if((add <0)||(add>0)){
try{
double d=Double.valueOf(a.trim()).doubleValue();
ans=add+d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException"+nfe.getMessage());
}
String result=String.valueOf(ans);
tf1.setText(result);
}
if((multiply <0)||(multiply>0)){
try{
double d=Double.valueOf(a.trim()).doubleValue();
ans=multiply*d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException"+nfe.getMessage());
}
String result=String.valueOf(ans);
tf1.setText(result);
}
if((div <0)||(div>0)){
try{
double d=Double.valueOf(a.trim()).doubleValue();
ans=div/d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException"+nfe.getMessage());
}
String result=String.valueOf(ans);
tf1.setText(result);
}
if((subtract <0)||(subtract>0)){
try{
double d=Double.valueOf(a.trim()).doubleValue();
ans=subtract-d;
}catch(NumberFormatException nfe){
System.out.println("NumberFormatException"+nfe.getMessage());
}
String result=String.valueOf(ans);
tf1.setText(result);
}
}
if(ae.getSource()==bMemCall){
// Display the number in memory
tf1.setText(Mem);
}
if(ae.getSource()==bClearMem){
// Clear the number in memory
Mem="";
tf1.setText(Mem);
}
if(ae.getSource()==bMemS){
// Save the number in memory
Mem=tf1.getText();
}
if(ae.getSource()==bMemSave){
// Save the number in memory
Mem=tf1.getText();
}
// Find the One Over X value of a number
if(ae.getSource()==boneorx){
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// For finding the one Over X value of the number
num = 1/d;
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
// Find the normal Logrithm of a number
if(ae.getSource()==bLog){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// Below is the formula for Changing "Natural Log" to "Log"
// 2.3026 is the constant value
num = Math.log(d)/2.3026;
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Find the natural log of a number
if(ae.getSource()==bnl){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// For finding the natural log of a number
num=Math.log(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// find the tangent of a number
if(ae.getSource()==bTan){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// For finding the tangent of the number
num = Math.tan(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Find the cos of a number
if(ae.getSource()==bCos){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// For finding the cos of the number
num = Math.cos(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Find the sin of a number
if(ae.getSource()==bSin){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// For finding the sin of the number
num = Math.sin(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Find the square of a number
if(ae.getSource()==bsqr){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
// we multiplied the number on itself so that we can get the square
num = d*d;
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Find the Cube of a number
if(ae.getSource()==bCube){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
// Changing the text of textfield from a string to double data type
double d = Double.valueOf(a.trim()).doubleValue();
// Multiplying the number 3 times so that we can get The cube
num = d*d*d;
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
// Converting the double data type to string data type
String result = String.valueOf(num);
// displaying the result in textfield
tf1.setText(result);
}
}
// Display the value of Pi which is 22/7
if(ae.getSource()==bPi){
String result = String.valueOf(Math.PI);
tf1.setText(result);
}
// Get the number from text field and round it
if(ae.getSource()==bRnd){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
num = Math.round(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Get The Number from TextField and change it to degrees
if(ae.getSource()==bDeg){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
num = Math.toDegrees(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Get the number from textfield and change it to radians
if(ae.getSource()==bRad){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
num = Math.toRadians(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
// Get the number from text field and change it to exponential form
if(ae.getSource()==bExp){
if(a.equals("")|(a==null)|(a=="0")){
//Do Nothing
}
else{
double num=0;
try {
double d = Double.valueOf(a.trim()).doubleValue();
num = Math.exp(d);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
String result = String.valueOf(num);
tf1.setText(result);
}
}
if(ae.getSource()==bc){
// Speed OF Light in Vaccum
String slc="299792458";
tf1.setText(slc);
}
if(ae.getSource()==bh){
// Plank Constant
String pc="6.626176e-34";
tf1.setText(pc);
}
if(ae.getSource()==bG){
//Gravitational Constant
String Gc ="6.672e-11";
tf1.setText(Gc);
}
if(ae.getSource()==be){
//Elementry Charge
String Ec="1.602189e-19";
tf1.setText(Ec);
}
if(ae.getSource()==bme){
//Electron Rest Mass
String erc="9.109534e-31";
tf1.setText(erc);
}
if(ae.getSource()==bu){
//Atomic Mass Unit
String amu="1.6605655e-27";
tf1.setText(amu);
}
if(ae.getSource()==bNA){
//Avogadro Constant
String ac="6.022045e23";
tf1.setText(ac);
}
if(ae.getSource()==bk){
//Boltzman Constant
String bc="1.380662e-23";
tf1.setText(bc);
}
if(ae.getSource()==bVm){
// Molar Volume of ideal gas at s.t.p.(Vm)
String mv="0.02241383";
tf1.setText(mv);
}
}
public void addComponent(Component c,int row,int col, int ncol,int nrow){
gbc.gridx=col;
gbc.gridy=row;

gbc.gridwidth=ncol;
gbc.gridheight=nrow;

gb.setConstraints(c,gbc);
add(c);
}
// The main Method of the class
public static void main(String args[]){
// Creating a new instance of the class
Main m=new Main("Calculator");
// Setting the size for the Frame
m.setSize(490,200);
// Setting the resizable property to false so that the frame cannot be resized
m.setResizable(false);
// setting the default location for the frame on the screen
m.setLocation(300,250);
// setting the image icon for the frame
// which will be displayed on the title bar
m.setIconImage(Toolkit.getDefaultToolkit().getImage("C:/Calculator/calc.jpg"));
// Setting the Frame Visible
m.setVisible(true);
}
}
   <<Less
About | Sitemap | Contact