package Taller;
import javax.swing.*;
import java.awt.Event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Area_Rectangulo extends JFrame implements ActionListener {
JLabel titulo1;
JLabel base;
JLabel altura;
JLabel resultado;
JTextField b;
JTextField a;
JButton calcular;
public Area_Rectangulo(){
setLayout(null);
titulo1=new JLabel("AREA DEL RECTANGULO");
titulo1.setBounds(20, 10, 200, 20);
add(titulo1);
base=new JLabel("Ingrese la base: ");
base.setBounds(20, 60, 200, 20);
add(base);
altura=new JLabel("ingrese la altura: ");
altura.setBounds(20, 80, 200, 20);
add(altura);
b=new JTextField();
b.setBounds(130, 60, 60, 20);
add(b);
a=new JTextField();
a.setBounds(130, 80, 60, 20);
add(a);
calcular=new JButton("CALCULAR");
calcular.setBounds(20, 120, 100, 20);
add(calcular);
calcular.addActionListener(this);
resultado=new JLabel("El area del rectangulo es: ");
resultado.setBounds(20, 180, 200, 20);
add(resultado);
}
public void actionPerformed(ActionEvent e){
Area_Rectangulo obj = new Area_Rectangulo();
if(e.getSource()==calcular){
double B=Double.parseDouble(b.getText());//Convertir texto a un double
double A=Double.parseDouble(a.getText());
double Area;
Area=A*B;
resultado.setText("El area del rectangulo es: "+Area);
}
}
public static void main(String[] args) {
Area_Rectangulo form = new Area_Rectangulo();
form.setBounds(0, 0, 400, 250);
form.setVisible(true);
}
}