calculator and facorial program using event handling
calculator and facorial program using event handling
*;
import java.applet.*;
import java.awt.event.*;
TextField t1,t2;
Label l1,l2;
Button b1,b2;
setLayout(new GridLayout(3,2));
l2=new Label("FACTORIAL");
t1=new TextField(15);
t2=new TextField(15);
b1=new Button("FACT");
add(l1);add(t1);
add(l2);add(t2);
add(b1);
b1.addActionListener(this);
int no;
int n=Integer.parseInt(t1.getText());
//if(ae.getSource()==b1)
//{
int fact=1;
for(int i=1;i<=n;i++)
fact=fact*i;
t2.setText(Integer.toString(fact));
//}
</applet>*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
TextField t1,t2,t3;
Label l1,l2,l3;
Button b1,b2,b3,b4;
setLayout(new GridLayout(5,2));
l3=new Label();
t1=new TextField(15);
t2=new TextField(15);
t3=new TextField(15);
b1=new Button("ADD");
b2=new Button("SUB");
b3=new Button("MUL");
b4=new Button("DIV");
add(l1);add(t1);
add(l2);add(t2);
add(l3);add(t3);
add(b1);add(b2);add(b3);add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
int no;
int n1=Integer.parseInt(t1.getText());
int n2=Integer.parseInt(t2.getText());
if(ae.getSource()==b1)
{int add=n1+n2;
l3.setText("addition");
t3.setText(Integer.toString(add));
if(ae.getSource()==b2)
{int sub=n1-n2;
l3.setText("substration");
t3.setText(Integer.toString(sub));
if(ae.getSource()==b3)
{int mul=n1*n2;
l3.setText("multi");
t3.setText(Integer.toString(mul));
if(ae.getSource()==b4)
{int div=n1/n2;
l3.setText("division");
t3.setText(Integer.toString(div));
}}}
</applet>*/