import java.awt.*;
import java.applet.*;
public class GUI3 extends Applet {
TextField xField;
TextField yField;
TextField answer;
Button eqButton;
Label plusLabel;
void eqButton_Clicked(Event event) {
// do this when the eqButton clicked,
int x=0,y=0;
// get the value of xField
String xS= xField.getText();
try{ x= Integer.parseInt(xS);}
catch( NumberFormatException e)
{ answer.setText("wrong number format!");}
// get the value of yField
String yS= yField.getText();
try{ y= Integer.parseInt(yS);}
catch( NumberFormatException e)
{ answer.setText("wrong number format!");}
// do the addition and display its result
int ans=x+y;
answer.setText(""+ans);
repaint();
}
public void init() {
// Layouting the gui parts.
setLayout(null); // Parts layout follows the geometric
// parameters of reshape.
xField = new TextField();
xField.reshape(20,20,60,30);
add(xField);
yField = new TextField();
yField.reshape(110,20,60,30);
add(yField);
answer = new TextField();
answer.reshape(220,20,60,30);
add(answer);
eqButton = new Button("=");
eqButton.reshape(180,20,30,30);
add(eqButton);
plusLabel = new Label("+");
plusLabel.reshape(90,20,20,30);
add(plusLabel);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == eqButton)
{
eqButton_Clicked(event);
}
}
}
/*<Applet code=GUI3.class width=400 height=400></Applet>*/