Thursday, October 14, 2010

JAVA CALCULATOR

import java.*;

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

/*<applet code="calculator" width=500 height=500>

</applet>*/

public class calculator extends Applet implements ActionListener

{

Label l1,l2;

Button b1,b2,b3,b4,b5;

TextField t1,t2;

public void init()                    

{

setLayout(null);

l1=new Label("number");

l2=new Label("number");

b1=new Button("add+");

b2=new Button("sub- ");

b3=new Button("mul*");

b4=new Button("div/");

b5=new Button("clear");

t1=new TextField(20);

t2=new TextField(20);

add(l1);

l1.setBounds(10,10,60,40);

add(l2);

l2.setBounds(10,70,60,40);

add(t1);

t1.setBounds(90,10,100,40);

add(t2);

t2.setBounds(90,70,100,40);

add(b1);

b1.setBounds(30,200,50,50);

add(b2);

b2.setBounds(100,200,50,50);

add(b3);

b3.setBounds(170,200,50,50);

add(b4);

b4.setBounds(240,200,50,50);

add(b5);

b5.setBounds(350,200,50,50);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

}

public void actionPerformed(ActionEvent e)

{

float a,b,c;

if(e.getSource()==b5)

{

t1.setText("");

t2.setText("");

t1.requestFocus();

}

a=Float.parseFloat(t1.getText());

b=Float.parseFloat(t2.getText());

showStatus("calculator");

if(e.getSource()==b1)

{

c=a+b;

t1.setText(""+c);

t2.setText("");

t2.requestFocus();

}

else if(e.getSource()==b2)

{

c=a-b;

t1.setText(""+c);

t2.setText("");

t2.requestFocus();

}

else if(e.getSource()==b3)

{

c=a*b;

t1.setText(""+c);

t2.setText("");

t2.requestFocus();

}

else if(e.getSource()==b4)

{

c=a/b;

t1.setText(""+c);

t2.setText("");

t2.requestFocus();

}

}

}












1 comment:

  1. The Casino at Wildhorse (Canada) - Mapyro
    This is a casino in 전라남도 출장마사지 the province 경상남도 출장샵 of St. George. The casino is owned by the Isle of Man Government 세종특별자치 출장샵 and operated 삼척 출장마사지 by the Isle of Man 서산 출장안마 and operated by  Rating: 4.3 · ‎44 reviews

    ReplyDelete

FOLLOWERS