Untitled
unknown
plain_text
a year ago
1.3 kB
18
Indexable
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Ventana extends JFrame {
JLabel etiqueta = new JLabel("Numeros:");
JTextField datoA = new JTextField(5);
JTextField datoB = new JTextField(5);
JLabel resultado = new JLabel("= ");
ActionListener accion = new ActionListener() {
public void actionPerformed(ActionEvent e) {
resultado.setText("= " + (
Integer.parseInt(datoA.getText()) +
Integer.parseInt(datoB.getText())));
}
};
JButton sumar = new JButton("SUMAR");
public Ventana() {
Container cont = getContentPane();
cont.setLayout(new FlowLayout());
cont.add(etiqueta);
cont.add(datoA);
cont.add(datoB);
cont.add(resultado);
sumar.addActionListener(accion);
cont.add(sumar);
// ACCION PARA CUANDO SE PIDE EL CIERRE DE LA VENTANA
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
}
class SumaSwing {
public static void main(String args[]) {
Ventana captura = new Ventana();
captura.setSize(250, 200);
captura.show();
}
}Editor is loading...
Leave a Comment