
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;
        

public class MiVentana extends JFrame implements ActionListener{
    private JButton miBoton;
    private JTextField miCampoTexto;
    private JLabel miEtiqueta;
    
    public MiVentana() {
        super("Mi Ventana");
        
        this.definirVentana();
        
        this.setSize(400, 400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        this.setVisible(true);
    }
    
    public void definirVentana() {
        this.setLayout(new FlowLayout());
        miBoton = new JButton("Enviar");
        miCampoTexto = new JTextField(20);
        miEtiqueta = new JLabel("algo");
        
        this.add(miCampoTexto);
        this.add(miBoton);
        this.add(miEtiqueta);
        miBoton.addActionListener(this);
    }

 
    public void actionPerformed(ActionEvent arg0) {
        if(arg0.getSource() == miBoton) {
            String a = miCampoTexto.getText();
            double val = 0; 
            try {
                val = Double.parseDouble(a);
            }
            catch (NumberFormatException ex) {
                miEtiqueta.setText("Error");
                miCampoTexto.setText("");
                return;
            }
            
            double val2 = val*1.1;
            miEtiqueta.setText("El 10% de " + val + " es " + val2);         
        }     
    }
     
}
