Write a program in Java to demonstrate Java Applet with parameter.
import java.awt.*;
import java.applet.*;
/*<applet code="AppletPara.class"height=300 width=300>
</applet>*/
public class AppletPara extends Applet
{ TextField text1,text2;
public void init( )
{ text1=new TextField(10);
text2=new TextField(10);
add(text1);
add(text2);
text1.setText("0");
text2.setText("0");
}
public void paint(Graphics g)
{ int x=0,y=0,z=0;
String s1,s2,s;
g.drawString("Input a number in each box ",10,50);
g.drawString("Press Enter For Result ",10,70);
try
{ s1=text1.getText();
x=Integer.parseInt(s1);
s2=text2.getText();
y=Integer.parseInt(s2);
}
catch(Exception e){ }
z=x+y;
s=String.valueOf(z);
g.drawString("The Sum is : ",10,90);
g.drawString(s,100,90);
}
public boolean action(Event event,Object obj)
{
repaint( );
return true;
}
}
0 Comments