packagetest;importjava.awt.Button;importjava.awt.Color;importjava.awt.FlowLayout;importjava.awt.Frame;importjava.awt.Label;importjava.awt.TextField;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;public class Round extends Frame implementsActionListener {
TextField t1, t2, t3, t4;
Button b1;
Button btnExit;publicRound() {
setLayout(newFlowLayout());
t1= new TextField(20);
t1.setBackground(Color.orange);
t2= new TextField(20);
t2.setBackground(Color.orange);
t3= new TextField(20);
t3.setBackground(Color.orange);
t4= new TextField(20);
t4.setBackground(Color.orange);
b1= new Button("计算");
btnExit= new Button("退出");
add(new Label("输入圆的半径:"));
add(t1);
add(new Label("得出圆的直径:"));
add(t2);
add(new Label("得出圆的面积:"));
add(t3);
add(new Label("得出圆的周长:"));
add(t4);
add(b1);
add(btnExit);
addWindowListener(newWindowAdapter() {public voidwindowClosing(WindowEvent e) {
System.exit(0);
}
});
b1.addActionListener(this);
btnExit.addActionListener(this);
setVisible(true);
setBounds(200, 200, 200, 300);
validate();
}public voidactionPerformed(ActionEvent e) {if (e.getSource() ==b1) {doubletemp, r, a, c;
temp=Float.parseFloat(t1.getText());
r= 2 *temp;
a= 3.14 * temp *temp;
c= 2 * 3.14 *temp;
t2.setText(String.valueOf(r));
t3.setText(String.valueOf(a));
t4.setText(String.valueOf(c));
}if (e.getSource() ==btnExit) {
System.exit(0);
}
}public static voidmain(String args[]) {newRound();
}
}