/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ExamenAdicional;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author felix
 */
public class Examen01 extends JFrame{
    private JLabel etiqueta;
    private JTextField campo;
    private JButton boton;
    private int cuenta;
    private Contador incrementa;
            
    public Examen01() {
        super("Mi Ventana");
        definirVentana();
        cuenta = 1;
        this.setSize(100, 200);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        incrementa.start();
    }
    
    public void definirVentana(){
        this.setLayout(new GridLayout(3,1));
        etiqueta = new JLabel();
        campo = new JTextField(20);
        boton = new JButton("Ok");
        
        boton.addActionListener(new Accion());
        this.add(etiqueta);
        this.add(campo);
        this.add(boton);
        incrementa = new Contador();
    }
    
    static public void main(String args[]) {
        new Examen01();
    }

    class Accion implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            campo.setText("Total " + cuenta);
        }
    }
    
    class Contador extends Thread{
        public void run(){
            while(true) {
                cuenta += 1;
                etiqueta.setText(puntos(cuenta));
                try {
                    sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Examen01.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        String puntos(int C) {
            int i, N;
            String aux = "       ";
            N = C%10 == 0 ? 10 : C%10;
            for(i=1; i<=N; i++)
                aux += ".";
            
            return aux;
        }
    }
}
