import java.awt.*;
import java.applet.*;
public class Appletdemo extends Applet
{
TextField text1,text2;
public void init()
{
text1=new TextField(10);
text2=new TextField(10);
add(text1);
add(text2);
text1.setText("");
text2.setText("");
}
public void paint(Graphics g)
{
int z=0,x=0,y=0;
String s1,s2,s;
g.drawString("input no in each textbox",10,50);
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,80);
g.drawString(s,100,80);
}
public boolean action(Event event,Object object)
{
repaint();
return true;
}
}
This is the code that i am trying to understand what is the need of
public boolean action(Event event,Object object)
{
repaint();
return true;
}
Why we are using it in our program.
This is an old construct used to handle
Actionevents from Java 1.0 prior to the use ofActionListeners.In Java 1.0 there was just one class of events, namely
java.awt.Event. Every event was generated by a component. One major problem with the model was that an event could only be handled by the component which generated it or by one of the containers that contained the original component.In Java 1.1 style event handling (using Event Listeners) known as the Delegation Event Model brought significant improvements. Here an event is sent only to objects that are listening for the event giving greater efficiency in event processing.
See: Java 1.0 Event Model