import javax.swing.*;
import java.awt.event.*;
public class Nene extends JFrame implements ActionListener{
private JLabel v1, v2, resu;
private JTextField esp1, esp2;
private JButton boton, boton1;
public Nene(){
setLayout(null);
v1 = new JLabel("Valor 1:");
v1.setBounds(50,5,100,30);
add(v1);
v2 = new JLabel("Valor 2:");
v2.setBounds(50,35,100,30);
add(v2);
esp1 = new JTextField();
esp1.setBounds(120,10,150,20);
add(esp1);
resu = new JLabel("Resultado:");
resu.setBounds(120,70,100,30);
add(resu);
esp2 = new JTextField();
esp2.setBounds(120,40,150,20);
add(esp2);
boton = new JButton("Sumar");
boton.setBounds(10,80,100,30);
add(boton);
boton.addActionListener(this);
boton1 = new JButton("Salir");
boton1.setBounds(100,80,100,30);
add(boton1);
boton1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == boton){
int valor1 = 0, valor2 = 0, res = 0;
valor1 = Integer.parseInt(v1.getText());
valor2 = Integer.parseInt(v2.getText());
res = valor1 + valor2;
resu.setText("Resultado: " + res);
}
if(e.getSource() == boton1){
System.exit(0);
}
}
public static void main(String args[]){
Nene formulario1 = new Nene();
formulario1.setBounds(0,0,500,150);
formulario1.setVisible(true);
formulario1.setLocationRelativeTo(null);
formulario1.setResizable(false);
}
}