import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Mycalc extends Applet implements ActionListener
{
Button b1,b2,b3,b4;
TextField t1,t2,t3;
public void init()
{
b1=new Button("Add");
b2=new Button("Subt");
b3=new Button("Mul");
b4=new Button("Divide");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
add (t1);
add (t2);
add (t3);
add (b1);
add (b2);
add (b3);
add (b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a+b;
String res=String.valueOf(c);
t3.setText(res);
}
if(ae.getSource()==b2)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a-b;
String res=String.valueOf(c);
t3.setText(res);
}
if(ae.getSource()==b3)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a*b;
String res=String.valueOf(c);
t3.setText(res);
}
if(ae.getSource()==b4)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a/b;
String res=String.valueOf(c);
t3.setText(res);
}
}
}
//<applet code=Mycalc height=500 width=600>
//</applet>
import java.applet.*;
import java.awt.event.*;
public class Mycalc extends Applet implements ActionListener
{
Button b1,b2,b3,b4;
TextField t1,t2,t3;
public void init()
{
b1=new Button("Add");
b2=new Button("Subt");
b3=new Button("Mul");
b4=new Button("Divide");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
add (t1);
add (t2);
add (t3);
add (b1);
add (b2);
add (b3);
add (b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a+b;
String res=String.valueOf(c);
t3.setText(res);
}
if(ae.getSource()==b2)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a-b;
String res=String.valueOf(c);
t3.setText(res);
}
if(ae.getSource()==b3)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a*b;
String res=String.valueOf(c);
t3.setText(res);
}
if(ae.getSource()==b4)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a/b;
String res=String.valueOf(c);
t3.setText(res);
}
}
}
//<applet code=Mycalc height=500 width=600>
//</applet>
No comments:
Post a Comment