lunes, 4 de abril de 2011

Código de la interacción con el usuario - Swing Java (13.01.04)



 

public class Ventana extends JFrame {

      JLabel etiqueta;
      JButton botonHola, botonAdios;
      // …
      public Ventana(){
            // …
            OyenteAccion oyenteBoton = new OyenteAccion();
            botonHola.addActionListener(oyenteBoton);
            botonAdios.addActionListener(oyenteBoton);
      }

      class OyenteAccion implements ActionListener {
            public void actionPerformed (ActionEvent evento) {
                  JButton boton = (JButton) evento.getSource();
                  etiqueta.setText(boton.getText() + " amigo! ");
            }
      }

}
Compartir:

0 comentarios:

Publicar un comentario