//使用CustomButton类的AveragingApplet小程序
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 Color newColor;
public Font newFont;
public CustomButton b1;
public int num1,num2;
public void init()
{
Panel p1;
newColor=new Color(125,0,255);
newFont=new Font("Helvetica",Font.BOLD+Font.ITALIC,18);
b1=new CustomButton("Push for Average",newColor,Color.yellow,newFont);
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");
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())));
}
/*
public void actionPerformed(ActionEvent e)
{
int num1,num2;
double avg;
num1=Integer.parseInt(input1.getText());
num2=Integer.parseInt(input2.getText());
avg=average.getAverage(num1,num2);
display.setText(""+avg);
}
*/
}