Welcome :Guest

Congratulations!!!

Top 5 Contributors of the Month
Melody Anderson

 Home >> Code Snippets >> OOPS >> Post New Resource

# Applet using arithmetic calculation.

Posted By:laptop charles       Posted Date: June 30, 2010    Points: 10    Category: OOPS    URL: http://www.dotnetspark.com

Arithmetic operation

It contain four operation.
```import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class app2 extends Applet implements ActionListener
{
Label l1,l2,l3;
TextField t1,t2,t3;
Button b1,b2,b3,b4;
public void init()
{
l1=new Label("ENTER THE NUMBER1");
l2=new Label("ENTER THE NUMBER2");
l3=new Label("RESULT");
t1=new TextField(20);
t2=new TextField(20);
t3=new TextField(20);
b2=new Button("multi");
b3=new Button("divid");
b4=new Button("sub");
}
public void actionPerformed(ActionEvent e)
{

Object obj=e.getSource();
if(obj==b1)
{
int a=Integer.parseInt(t1.getText());
int b= Integer.parseInt(t2.getText());
int c=a+b;
t3.setText(c+"");
}
else if(obj==b2)
{
int a=Integer.parseInt(t1.getText());
int b= Integer.parseInt(t2.getText());
int c=a*b;
t3.setText(c+"");
}
else if(obj==b3)
{
int a=Integer.parseInt(t1.getText());
int b= Integer.parseInt(t2.getText());
int c=a/b;
t3.setText(c+"");
}
else if(obj==b4)
{
int a=Integer.parseInt(t1.getText());
int b= Integer.parseInt(t2.getText());
int c=a-b;
t3.setText(c+"");
}
}
}

/*
*/```

Responses

No response found. Be the first to respond this post

Post Comment