lunes, 4 de abril de 2011

Resumen Delegacion de Eventos Java (13.03.04)

4.1. Crear la clase oyente
class OyenteAccion implements ActionListener {
}
4.2. Implementar en la clase oyente el método
public void actionPerformed (ActionEvent evento) {
JButton boton = (JButton) evento.getSource();
etiqueta.setText(boton.getText() + " amigo! ");
}
4.3. Crear un objeto de la clase oyente.
OyenteAccion oyenteBoton = new OyenteAccion();

4.4. Registrarlo como oyente en los componentes.
botonHola.addActionListener(oyenteBoton);
botonAdios.addActionListener(oyenteBoton);
Compartir:

0 comentarios:

Publicar un comentario