java - Input to an applet -
cannot understand use of :public boolean action(event event, object object) { repaint(); return true ; } }. making return sum of 2 numbers. if don't use.
public boolean action (event event, object object) { repaint(); return true ;
i can enter number in text field won't generate sum. why?
}} import java.awt.*; import java.applet .*; public class user extends applet{ textfield text1,text2; public void init(){ text1=new textfield(8); text2=new textfield(8); 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 no in.each box",10,50); try{ s1=text1.gettext(); x=integer.parseint(s1); s2=text1.gettext(); y=integer.parseint(s2); } catch(exception e){} z=x +y ; s=string.valueof(z); g.drawstring("the sum is:",10,75); g.drawstring(s,100,75); } public boolean action (event event, object object ) { repaint(); return true ; }}
you need change line:
public boolean action (event event, object object )
to this:
public boolean action (event event, object object )
note lowercase b
in boolean
. boolean
, boolean
not same thing.
Comments
Post a Comment