/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Capitulo_6.Ventana;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author felix
 */
public class MiVentana extends JFrame implements ActionListener {
    private JButton miBoton;
    private JTextField miCampoTexto;
    private JLabel miEtiqueta;
    
    public MiVentana() {
        super("Mi Ventana");
        definirVentana();
        this.setSize(400,400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    
    private void definirVentana() {
        this.setLayout(new FlowLayout());
        miBoton = new JButton("Ok");
        miCampoTexto = new JTextField(20);
        miEtiqueta = new JLabel("Dame tu clave de acceso");
        
        this.add(miEtiqueta);
        this.add(miCampoTexto);
        this.add(miBoton);
        miBoton.addActionListener(this);
        
    }

    static public void main(String args[]) {
        MiVentana a = new MiVentana();
    }

    public void actionPerformed(ActionEvent arg0) {
        if(arg0.getSource()==miBoton){
            miEtiqueta.setText(miCampoTexto.getText());
            miCampoTexto.setText("");
        }
    }
}
