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


public class SwingExemplo4 extends JFrame
{
   private JButton butOK, butLimpar; 
   private JTextField campo1,campo2,campoR; 
   private JLabel texto1,texto2,textoR; 
   private JPanel p1 = new JPanel(); 
   private JPanel p2 = new JPanel();
   
   private Container c;
   
   public SwingExemplo4()
   {
      super("Aplicacao grafica simples");
      
      // Cria os componentes 
      texto1  = new JLabel("Nome:");
      campo1  = new JTextField(15);
      texto2  = new JLabel("Fone:");
      campo2  = new JTextField(15);
      textoR  = new JLabel("Resp:");
      campoR  = new JTextField(15);
      
      butOK   = new JButton("OK");
      butOK.addActionListener(
                              new ActionListener()
                                 {
         public void actionPerformed(ActionEvent e)
         {
            campoR.setText(campo1.getText()+" - "+campo2.getText());
         }
      } );
      
      butLimpar   = new JButton("Limpar");
      butLimpar.addActionListener(
                                  new ActionListener()
                                     {
         public void actionPerformed(ActionEvent e)
         {
            campo1.setText("");
            campo2.setText(""); 
            campoR.setText("");
         }
      } );
      
      campoR.setEnabled(false);
      // Define o layout do container básico   
      
      c = getContentPane();
      c.setLayout(new GridLayout(2,1));
      
      // Define o layout dos Panels
      p1.setLayout(new GridLayout(3,2)); 
      p2.setLayout(new FlowLayout(FlowLayout.CENTER));  
      // Adiciona os componentes aos panels 
      p1.add(texto1); p1.add(campo1); 
      p1.add(texto2); p1.add(campo2); 
      p1.add(textoR);
      p1.add(campoR);
      p2.add(butOK);
      p2.add(butLimpar); 
      // Adiciona os panels ao container básico 
      c.add(p1);
      c.add(p2);
      pack();
      show();
   } 
   
   public static void main(String args[]) 
   { 
      SwingExemplo4 ap=new SwingExemplo4();
      ap.addWindowListener(
                           new WindowAdapter()
                              {
         public void windowClosing(WindowEvent e)
         {
            System.exit(0);
         }
      }
      );
   } 
}