Reputation: 71
Cannot understand the use of :public boolean action(Event event, Object object) { repaint(); return true ; } }. Am making an that would return the sum of two numbers. If I don't use.
Public boolean action (Event event, Object object) {
repaint();
return true ;
I can enter the number in the text field but it won't generate the 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 a 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 ;
}}
Upvotes: 0
Views: 147
Reputation: 2466
You're returning a Boolean wrapper object instead of a primitive Boolean. Change your return type to 'boolean' (Lowercase)
Upvotes: 1
Reputation: 21184
You need to change this line:
public Boolean action (Event event, Object object )
to this:
public boolean action (Event event, Object object )
Note the lowercase b
in boolean
. Boolean
and boolean
are not the same thing.
Upvotes: 2