Sum of Two number java applet
/* <applet code="sumOf2No" height=150 width =350> </applet> */
import java.awt.*;
import java.applet.*;
publicclass sumOf2No extends Applet
{
TextField T1,T2;
publicvoid init() {
T1 = new TextField(10);
T2 = new TextField(10);
add(T1);
add(T2);
T1.setText("0");
T2.setText("0");
}
publicvoid paint(Graphics g) {
int a, b, result;
String str;
g.drawString("Enter Number in TextField to Find addition of 2 No ",10,50);
g.setColor(Color.red);
str=T1.getText();
a=Integer.parseInt(str);
str=T2.getText();
b=Integer.parseInt(str);
result=a+b;
g.drawString("After Addition the Result is : "+result,10,80);
showStatus("Addition of 2 Numbers");
}
public boolean action(Event e, Object o){
repaint();
returntrue;
}
}
Comments
Post a Comment