       import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
       import javax.swing.border.*;

       public class TestWindow extends JFrame
       implements ActionListener
       {
       private JTextField radiusIn, sideIn,perimeter1, area1,perimeter2,area2;
       private JButton jButton1 ;
       public TestWindow()
       {
       super("求解图形周长和面积");
       JPanel view = new JPanel();
       view.setLayout(new GridLayout(8, 2, 10, 10));
       view.setBorder(new EmptyBorder(10,10,10,10));

       view.add(new JLabel("圆半径 = ", SwingConstants.RIGHT));
       radiusIn = new JTextField(8);

       view.add(radiusIn);
       view.add(new JLabel("周长 = ",	SwingConstants.RIGHT));
       perimeter1 = new JTextField(8);
       view.add(perimeter1);

       view.add(new JLabel("面积 = ", SwingConstants.RIGHT));
       area1 = new JTextField(8);
       view.add(area1) ;
//------------------------------------------------------------
       view.add(new JLabel("正方形边长 = ", SwingConstants.RIGHT));
       sideIn = new JTextField(8);
       view.add(sideIn);

       view.add(new JLabel("周长 = ",	SwingConstants.RIGHT));
       perimeter2 = new JTextField(8);
       view.add(perimeter2);

       view.add(new JLabel("面积 = ", SwingConstants.RIGHT));
       area2 = new JTextField(8);
       view.add(area2);

       view.add (new JPanel()); // reserved
       Container c = getContentPane();
       c.add(view, BorderLayout.NORTH);
       jButton1=new JButton("OK");
       jButton1.addActionListener(this);
       c.add(jButton1,BorderLayout.SOUTH );
       }


       public void actionPerformed(ActionEvent e)
       {

       String s = radiusIn.getText();
       double r = Double.parseDouble(s);
       Circle c1 = new Circle(r);
       radiusIn.setText(" " + r);
       perimeter1.setText(" 	" + c1.perimeter());
       area1.setText(" " + c1.area());
       s=sideIn.getText();
       double side= Double.parseDouble(s);
       Square s1=new Square(side);
       perimeter2.setText(" 	" + s1.perimeter());
       area2.setText(" " + s1.area());
       }


       public static void main(String[] args)

       {
       TestWindow w = new TestWindow();
       w.setSize(320, 280);
       w.addWindowListener(new WindowAdapter()
        {  public void windowClosing(WindowEvent e)
          {    System.exit(0); } });
       w.show();
       }
       }
