import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//<applet code=CustomAverage.class width=400 height=300></applet>
public class CoustomAverage
{
public double average;
public CustomAverage()
{
average=0.0;
}
public double getAverage(int num1,int num2)
{
average=((double)num1+num2)/2;
return average;
}
}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//<applet code=AverageApplet.class width=400 height=300></applet>
public class AverageApplet extends Applet implements ActionListener
{
public CustomAverage average;
public TextField input1,input2,display;
public Label labelTitle,label1input,label2input,label3display;
public Button b1;
public int num1,num2;
public void init()
{
Panel p1;
average=new CustomAverage();
input1=new TextField(12);
input2=new TextField(12);
display=new TextField(12);
input1.setText("0");
input2.setText("0");
display.setText("");
display.setEditable(false);
labelTitle=new Label("Average Calculator");
label1input=new Label("First Number");
label2input=new Label("Second Number");
label3display=new Label("Computed Average");
b1=new Button("Push to Compute Average");
p1=new Panel(new GridLayout(8,1,10,10));
b1.addActionListener(this);
p1.add(labelTitle);p1.add(label1input);p1.add(input1);
p1.add(label2input);p1.add(input2);
p1.add(b1);p1.add(label3display);p1.add(display);add(p1);
}
public void actionPerformed(ActionEvent e)
{
display.setText(""+average.getAverage(Integer.parseInt(input1.getText()),
Integer.parseInt(input2.getText())));
}
}