/*
 * 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 Capitulo_8.prueba;

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;

/**
 *
 * @author felix
 */
public class UnFrame extends JFrame {
    private JTextField texto1;
    private JTextField texto2;
    private ActulizaCampo cambia;
    
    public UnFrame(){
        super("Prueba");
        definirVentana();
        cambia = new ActulizaCampo();
        cambia.start();
        this.setSize(400, 400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);   
    }
    
    public void definirVentana() {
        this.setLayout(new FlowLayout());
        texto1 = new JTextField(20);
        texto2 = new JTextField(20);
        this.add(texto1);
        this.add(texto2);
    }    
    
    static public void main(String args[]) {
        new UnFrame();
    }

    private class ActulizaCampo extends Thread{  
        public void run(){
            String aux;
            double val;
            while(true) {
                aux = texto1.getText();
                
                try  {
                    val = Double.parseDouble(aux);
                    aux = ""+ (val*9.0/5.0 + 32.0);

                    texto2.setText(aux);
                }
                catch(NumberFormatException e) {
                   texto2.setText("0"); 
                }
                
                try {
                    sleep(10);
                }
                catch (InterruptedException ex) {
                }
            }
        }
    }
}
