Você está na página 1de 1

/* AN APPLET PROGRAM TO DISPLAY SUM OF TWO NUMBERS IN TEXTFIELD *?

/* An applet program that concatenates two string entered in TextField in Java */


/* <applet code="sumOf2No" height=200 width =400> </applet> */
/* <applet code="concat2Str.class" height=150 width=350> </applet> */
import java.awt.*;
import java.applet.*; import java.awt.*;
public class sumOf2No extends Applet import java.applet.*;
{
TextField T1,T2; public class concat2Str extends Applet
public void init() {
{ TextField Ts1,Ts2;
T1 = new TextField(10);
T2 = new TextField(10); public void init()
add(T1); {
add(T2); Ts1 = new TextField(10);
T1.setText(""); Ts2 = new TextField(10);
T2.setText(""); add(Ts1);
} add(Ts2);
Ts1.setText("");
public void paint(Graphics g) Ts2.setText("");
{ }
int a, b, result; public void paint(Graphics g)
String str; {
g.drawString("Enter Number in TextField to Find addition of 2 No ",10,50); String str1,str2;
g.setColor(Color.red); g.drawString("Enter Two Strings to Concatenate: ",10,50);
str=T1.getText(); str1=Ts1.getText();
a=Integer.parseInt(str); str2=Ts2.getText();
str=T2.getText(); g.setColor(Color.red);
b=Integer.parseInt(str); g.drawString(str1+" "+str2,10,70);
result=a+b; showStatus("The entered two strings are concatenated successfully");
g.drawString("After Addition the Result is : "+result,10,80); }
showStatus("Addition of 2 Numbers"); public boolean action(Event e, Object o)
} {
public boolean action(Event e, Object o) repaint();
{ return true;
repaint(); }
return true; }
}
}

Você também pode gostar