import javax.swing.*;
import java.awt.event.*;
public class Formulario10 extends JFrame implements ActionListener{
private JLabel label1, label2, label3, label4;
private JTextField text1, text2;
private JTextArea area1;
private JButton boton1;
public Formulario10(){
setLayout(null);
label1 = new JLabel("Programa para sumar");
label1.setBounds(100,8,180,27);
add(label1);
label2 = new JLabel("Numero 1:");
label2.setBounds(10,55,300,27);
add(label2);
label3 = new JLabel("Numero 2:");
label3.setBounds(10,120,290,27);
add(label3);
label4 = new JLabel("Resultado:");
label4.setBounds(10,185,290,27);
add(label4);
text1 = new JTextField();
text1.setBounds(75,57,160,26);
add(text1);
text2 = new JTextField();
text2.setBounds(75,123,160,26);
add(text2);
area1 = new JTextArea();
area1.setBounds(75,187,160,24);
area1.setEditable(false);
add(area1);
boton1 = new JButton("+");
boton1.setBounds(250,80,40,40);
add(boton1);
boton1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == boton1){
int valor1 = 0, valor2 = 0, resultado = 0;
valor1 = Integer.parseInt(text1.getText());
valor2 = Integer.parseInt(text2.getText());
resultado = valor1 + valor2;
area1.setText(resultado);
}
}
public static void main(String args[]){
Formulario10 interfaz = new Formulario10();
interfaz.setBounds(0,0,330,270);
interfaz.setVisible(true);
interfaz.setResizable(false);
interfaz.setLocationRelativeTo(null);
}
}